Skip to content

Commit

Permalink
fix: animator.sprite was redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Piętal committed May 22, 2024
1 parent 9910dc8 commit cf381d9
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 87 deletions.
2 changes: 1 addition & 1 deletion dist/animator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions dist/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Animator extends PIXI.Container {
* @param texture
*/
constructor(gameObject, { animations, cols, rows, animationSpeed = 16.67, anchor = { x: 0.5, y: 0.5 } }, { width, height, source }) {
var _a;
super();
/**
* When Lifecycle Object is updated, it emits this subject.
Expand All @@ -57,7 +56,6 @@ class Animator extends PIXI.Container {
this.label = 'Animator';
gameObject.addChild(this);
this.stateMachine = new state_machine_1.StateMachine(gameObject);
this.sprite = new PIXI.Container();
const tileWidth = width / cols;
const tileHeight = height / rows;
Object.values(animations).forEach((animationFrames) => {
Expand All @@ -69,10 +67,9 @@ class Animator extends PIXI.Container {
return { texture, time: animationSpeed };
}));
animatedSprite.anchor.set(anchor.x, anchor.y);
this.sprite.addChild(animatedSprite);
this.addChild(animatedSprite);
});
this.states = Object.keys(animations);
(_a = gameObject.scene) === null || _a === void 0 ? void 0 : _a.stage.addChild(this.sprite);
}
/**
* Reference to inner State Machine's state.
Expand All @@ -93,12 +90,12 @@ class Animator extends PIXI.Container {
return this.animation.scale;
}
update(deltaTime) {
this.sprite.x = this.gameObject.x;
this.sprite.y = this.gameObject.y;
this.x = this.gameObject.x;
this.y = this.gameObject.y;
lifecycle_1.Lifecycle.update(this, deltaTime);
}
setScale(x = 1, y = x) {
this.sprite.children.forEach((child) => {
this.children.forEach((child) => {
child.scale.set(x, y);
});
}
Expand All @@ -110,7 +107,7 @@ class Animator extends PIXI.Container {
if (animation === this.animation) {
return;
}
const children = this.sprite.children.filter((child) => child instanceof PIXI.AnimatedSprite && child !== animation);
const children = this.children.filter((child) => child instanceof PIXI.AnimatedSprite && child !== animation);
children.forEach((child) => {
child.visible = false;
child.stop();
Expand All @@ -132,7 +129,7 @@ class Animator extends PIXI.Container {
if (!this.stateMachine.setState(next)) {
return '';
}
const animation = this.sprite.children[index];
const animation = this.children[index];
if (!loop && stateWhenFinished) {
animation.onComplete = () => {
animation.onComplete = null;
Expand Down
84 changes: 42 additions & 42 deletions docs/classes/Animator.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ <h4>Implements</h4>
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L18"
>src/animator.ts:18</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L17"
>src/animator.ts:17</a
>
</li>
</ul>
Expand Down Expand Up @@ -1433,8 +1433,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L71"
>src/animator.ts:71</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L70"
>src/animator.ts:70</a
>
</li>
</ul>
Expand Down Expand Up @@ -2091,8 +2091,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L64"
>src/animator.ts:64</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L63"
>src/animator.ts:63</a
>
</li>
</ul>
Expand Down Expand Up @@ -2206,8 +2206,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L34"
>src/animator.ts:34</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L33"
>src/animator.ts:33</a
>
</li>
</ul>
Expand Down Expand Up @@ -2475,8 +2475,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L29"
>src/animator.ts:29</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L28"
>src/animator.ts:28</a
>
</li>
</ul>
Expand Down Expand Up @@ -2738,8 +2738,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L49"
>src/animator.ts:49</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L48"
>src/animator.ts:48</a
>
</li>
</ul>
Expand Down Expand Up @@ -3134,8 +3134,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L54"
>src/animator.ts:54</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L53"
>src/animator.ts:53</a
>
</li>
</ul>
Expand Down Expand Up @@ -4971,8 +4971,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L44"
>src/animator.ts:44</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L43"
>src/animator.ts:43</a
>
</li>
</ul>
Expand Down Expand Up @@ -5009,8 +5009,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L39"
>src/animator.ts:39</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L38"
>src/animator.ts:38</a
>
</li>
</ul>
Expand Down Expand Up @@ -5040,8 +5040,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L59"
>src/animator.ts:59</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L58"
>src/animator.ts:58</a
>
</li>
</ul>
Expand Down Expand Up @@ -5148,8 +5148,8 @@ <h3 class="tsd-anchor-link">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L23"
>src/animator.ts:23</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L22"
>src/animator.ts:22</a
>
</li>
</ul>
Expand Down Expand Up @@ -6020,8 +6020,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L134"
>src/animator.ts:134</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L129"
>src/animator.ts:129</a
>
</li>
</ul>
Expand Down Expand Up @@ -6138,8 +6138,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L120"
>src/animator.ts:120</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L115"
>src/animator.ts:115</a
>
</li>
</ul>
Expand Down Expand Up @@ -6184,8 +6184,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L127"
>src/animator.ts:127</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L122"
>src/animator.ts:122</a
>
</li>
</ul>
Expand Down Expand Up @@ -7907,8 +7907,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L152"
>src/animator.ts:152</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L147"
>src/animator.ts:147</a
>
</li>
</ul>
Expand Down Expand Up @@ -8443,8 +8443,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L208"
>src/animator.ts:208</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L203"
>src/animator.ts:203</a
>
</li>
</ul>
Expand Down Expand Up @@ -8506,8 +8506,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L212"
>src/animator.ts:212</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L207"
>src/animator.ts:207</a
>
</li>
</ul>
Expand Down Expand Up @@ -10432,8 +10432,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L158"
>src/animator.ts:158</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L153"
>src/animator.ts:153</a
>
</li>
</ul>
Expand Down Expand Up @@ -10636,8 +10636,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L144"
>src/animator.ts:144</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L139"
>src/animator.ts:139</a
>
</li>
</ul>
Expand Down Expand Up @@ -10811,8 +10811,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L179"
>src/animator.ts:179</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L174"
>src/animator.ts:174</a
>
</li>
</ul>
Expand Down Expand Up @@ -11208,8 +11208,8 @@ <h4 class="tsd-returns-title">
<li>
Defined in
<a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L138"
>src/animator.ts:138</a
href="https://github.com/Prozi/oneforall/blob/main/src/animator.ts#L133"
>src/animator.ts:133</a
>
</li>
</ul>
Expand Down
17 changes: 6 additions & 11 deletions docs/demo/demo.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -88021,7 +88021,6 @@ Deprecated since v${version}`
},
{ width, height, source }
) {
var _a;
super();
/**
* When Lifecycle Object is updated, it emits this subject.
Expand All @@ -88043,7 +88042,6 @@ Deprecated since v${version}`
this.label = 'Animator';
gameObject.addChild(this);
this.stateMachine = new state_machine_1.StateMachine(gameObject);
this.sprite = new PIXI.Container();
const tileWidth = width / cols;
const tileHeight = height / rows;
Object.values(animations).forEach((animationFrames) => {
Expand All @@ -88062,12 +88060,9 @@ Deprecated since v${version}`
})
);
animatedSprite.anchor.set(anchor.x, anchor.y);
this.sprite.addChild(animatedSprite);
this.addChild(animatedSprite);
});
this.states = Object.keys(animations);
(_a = gameObject.scene) === null || _a === void 0
? void 0
: _a.stage.addChild(this.sprite);
}
/**
* Reference to inner State Machine's state.
Expand All @@ -88088,12 +88083,12 @@ Deprecated since v${version}`
return this.animation.scale;
}
update(deltaTime) {
this.sprite.x = this.gameObject.x;
this.sprite.y = this.gameObject.y;
this.x = this.gameObject.x;
this.y = this.gameObject.y;
lifecycle_1.Lifecycle.update(this, deltaTime);
}
setScale(x = 1, y = x) {
this.sprite.children.forEach((child) => {
this.children.forEach((child) => {
child.scale.set(x, y);
});
}
Expand All @@ -88107,7 +88102,7 @@ Deprecated since v${version}`
if (animation === this.animation) {
return;
}
const children = this.sprite.children.filter(
const children = this.children.filter(
(child) =>
child instanceof PIXI.AnimatedSprite && child !== animation
);
Expand All @@ -88132,7 +88127,7 @@ Deprecated since v${version}`
if (!this.stateMachine.setState(next)) {
return '';
}
const animation = this.sprite.children[index];
const animation = this.children[index];
if (!loop && stateWhenFinished) {
animation.onComplete = () => {
animation.onComplete = null;
Expand Down
Loading

0 comments on commit cf381d9

Please sign in to comment.