Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
[feat]The new way to instruct father and son objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Apr 21, 2023
1 parent c521bd1 commit 996b289
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
27 changes: 3 additions & 24 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,6 @@ export class Core implements IRenderable, IRendererController {
// this.#frameImmediately = 0;
if (this.#ctx === null) return;
this.#start && this.#start();
// eslint-disable-next-line no-constant-condition
const draw = (children: Carobj[], father?: Carobj) => {
children.forEach((child) => {
const oldX = child.x;
const oldY = child.y;
// const oldRotationCenterX = child.rotationCenterX;
// const oldRotationCenterY = child.rotationCenterY;
if (typeof father === "undefined") {
child.onUpdate(this.#ctx!);
} else {
child.x += father.x;
child.y += father.y;
// child.rotationCenterX += father.x;
// child.rotationCenterY += father.y;
child.onUpdate(this.#ctx!);
}
draw(child.children, child);
child.x = oldX;
child.y = oldY;
// child.rotationCenterX = oldRotationCenterX;
// child.rotationCenterY = oldRotationCenterY;
});
};
setInterval(() => {
this.#ctx?.clearRect(0, 0, this.#ele.width, this.#ele.height);
// console.log(this.#frameImmediately, this.isSuspend);
Expand All @@ -94,7 +71,9 @@ export class Core implements IRenderable, IRendererController {
this.#every?.forEach((each) => {
each && each(this.#frameImmediately);
});
draw(this.#objects);
this.#objects.forEach((object) => {
object.onUpdate(this.#ctx!);
})
}, 1000 / this.#fps);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/objects/src/lib/carobj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ export class Carobj implements IPositionedMut, IRotatedMut, IScaledMut {
if (this.display === true) {
ctx.save();
ctx.translate(this.#rotationCenterX, this.#rotationCenterY);
console.log(this.#rotationCenterX, this.#x, this.#rotationCenterY, this.#y);
// ctx.translate(this.#x, this.#y);
ctx.rotate(this.#rotation);
ctx.scale(this.#scaleX, this.#scaleY);
ctx.globalCompositeOperation = this.#operation;
this.onDraw(ctx);
this.#children.forEach((child) => {
child.onUpdate(ctx);
})
ctx.restore();
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/testmain/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
animation.addObject(circle);

animation.onUpdate((currentFrame) => {
littleCircle.rotation += 5;
circle.rotation += 1;
})

animation.startPlay();
Expand Down

0 comments on commit 996b289

Please sign in to comment.