mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-06-09 00:38:00 +08:00
fix: 优化 save 的调用次数
This commit is contained in:
parent
c79bcaeaa2
commit
724eabd49a
@ -269,9 +269,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
if (this.cacheDirty) {
|
if (this.cacheDirty) {
|
||||||
const { canvas } = this.cache;
|
const { canvas } = this.cache;
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.save();
|
|
||||||
this.render(this.cache, tran);
|
this.render(this.cache, tran);
|
||||||
ctx.restore();
|
|
||||||
this.cacheDirty = false;
|
this.cacheDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,18 +103,15 @@ export class Animate extends Sprite {
|
|||||||
super('absolute', false, true);
|
super('absolute', false, true);
|
||||||
|
|
||||||
this.setRenderFn((canvas, transform) => {
|
this.setRenderFn((canvas, transform) => {
|
||||||
const { ctx } = canvas;
|
|
||||||
if (
|
if (
|
||||||
this.absoluteAnimates.size === 0 &&
|
this.absoluteAnimates.size === 0 &&
|
||||||
this.staticAnimates.size === 0
|
this.staticAnimates.size === 0
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx.save();
|
|
||||||
this.drawAnimates(this.absoluteAnimates, canvas);
|
this.drawAnimates(this.absoluteAnimates, canvas);
|
||||||
transformCanvas(canvas, transform);
|
transformCanvas(canvas, transform);
|
||||||
this.drawAnimates(this.staticAnimates, canvas);
|
this.drawAnimates(this.staticAnimates, canvas);
|
||||||
ctx.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.delegation = this.delegateTicker(time => {
|
this.delegation = this.delegateTicker(time => {
|
||||||
|
@ -33,9 +33,7 @@ export class Sprite<
|
|||||||
canvas: MotaOffscreenCanvas2D,
|
canvas: MotaOffscreenCanvas2D,
|
||||||
transform: Transform
|
transform: Transform
|
||||||
): void {
|
): void {
|
||||||
canvas.ctx.save();
|
|
||||||
this.renderFn(canvas, transform);
|
this.renderFn(canvas, transform);
|
||||||
canvas.ctx.restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setRenderFn(fn: RenderFunction) {
|
setRenderFn(fn: RenderFunction) {
|
||||||
|
Loading…
Reference in New Issue
Block a user