fix: 优化 save 的调用次数

This commit is contained in:
unanmed 2024-11-06 21:06:59 +08:00
parent c79bcaeaa2
commit 724eabd49a
3 changed files with 0 additions and 7 deletions

View File

@ -269,9 +269,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
if (this.cacheDirty) {
const { canvas } = this.cache;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
this.render(this.cache, tran);
ctx.restore();
this.cacheDirty = false;
}

View File

@ -103,18 +103,15 @@ export class Animate extends Sprite {
super('absolute', false, true);
this.setRenderFn((canvas, transform) => {
const { ctx } = canvas;
if (
this.absoluteAnimates.size === 0 &&
this.staticAnimates.size === 0
) {
return;
}
ctx.save();
this.drawAnimates(this.absoluteAnimates, canvas);
transformCanvas(canvas, transform);
this.drawAnimates(this.staticAnimates, canvas);
ctx.restore();
});
this.delegation = this.delegateTicker(time => {

View File

@ -33,9 +33,7 @@ export class Sprite<
canvas: MotaOffscreenCanvas2D,
transform: Transform
): void {
canvas.ctx.save();
this.renderFn(canvas, transform);
canvas.ctx.restore();
}
setRenderFn(fn: RenderFunction) {