Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tween._inited does not reset if scene is being destroyed or removed inside the game and rebuild #92

Open
simongcc opened this issue Jan 26, 2017 · 1 comment
Assignees

Comments

@simongcc
Copy link

I have written a game using easeljs + preloadjs + soundjs + tweenjs.
The scene order like this:
I used the same canvas for different scene. Promo Scene -> Start Game Scene
Every time finishing the game, the restart button will go to Promo Scene again.

I found that probably(I haven't dig deep enough to find out) I use stage.clear(), stage.removeAllEventListeners() and so on.
The Tween ticker is somehow being removed from the scene.
So, first run, everything is fine, afterward, the Tween does not run unless I set Tween._inited = false before anything start again. Since the big Tween is supposed to be added once as tick function according to the source code logic.

I add this in restart game logic createjs.Tween._inited = false; as workaround.
Since _inited is undocumented due to it is an internal property.

I think it is an issue for restarting everything, in the above situation, but not necessarily a bug.

if (!Tween._inited && createjs.Ticker) {
	console.log("init Tween");
	createjs.Ticker.addEventListener("tick", Tween); Tween._inited = true; 
}
@spassvogel
Copy link

spassvogel commented Jun 2, 2017

I have been dealing with the same issue. This is what happens:

  1. Our game is over, so we destroy everything and call Ticker.reset
  2. All 'tick' event listeners are removed BUT Tween._inited is still true
  3. When we start a new game and try to create a new tween, Tween thinks it's initialized but there is no 'tick' listener on Ticker.

@simongcc has a solution, I have solved it differently, by explicitly setting Tween._inited = false when we destroy our game, because registering a new tween automatically adds the 'tick' listener if _inited is false.

if (!Tween._inited && createjs.Ticker) { createjs.Ticker.addEventListener("tick", Tween); Tween._inited = true; }

However, setting protected properties like that is not recommended practice. I would humbly request the devs to create a public Tween.reset() or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants