Maybe an bug about change scene stuff


#1

Hi i maybe found a bug about change scene stuff

19:27:04~~> start change Scene2~~> Scene1

MyAppScene1 onEnter Start
19:27:04~~> MyAppScene1Layer init
19:27:04~~> MyAppScene1Layer onEnter
19:27:04~~> MyAppScene1Layer onEnterTransitionDidFinish
19:27:04~~> MyAppScene1Layer has been add to scene
MyAppScene1 onEnter End

19:27:06~~> MyAppScene2Layer onExit
19:27:06~~> MyAppScene2 onExit
19:27:06~~> MyAppScene1Layer onEnterTransitionDidFinish
19:27:06~~> MyAppScene1 onEnterTransitionDidFinish
19:27:06~~> MyAppScene2Layer on cleanup
19:27:06~~> MyAppScene2 on cleanup

as you can see , the function “onEnter” and “onEnterTransitionDidFinish” has been called twice during change scene,

i checked the code in CCNode.js

the code line 1010~1014 during addChild function is

child.setParent(this);
if (this.*running) {
child.onEnter;
child.onEnterTransitionDidFinish;
}
so, when the MyAppScene1Layer has been add to scene MyAppScene1 , the two function will be called once,
and after the scene change finish , the two function will call again.

=
var MyAppScene1 = cc.Scene.extend {
this.*super();
cc.log(“MyAppScene1 onEnter Start”);
var layer = new MyAppScene1Layer();
layer.init();
this.addChild(layer);
cc.log(DataUtils.getCurrentTimeStr() + “MyAppScene1Layer has been add to scene”);
cc.log(“MyAppScene1 onEnter End”);
},

var changeSceneItem = cc.MenuItemImage.create(“res/CloseNormal.png”, “res/CloseSelected.png”, function() {
cc.log(DataUtils.getCurrentTimeStr() + “start change Scene1 -> Scene2”);
var scene = new MyAppScene2();
cc.Director.getInstance().replaceScene(cc.TransitionFade.create(2, scene));
});

so is this an bug or i wrote the code in wrong way?

thanks

Eran


#2

Can you please format your code so it can be read, 4 spaces please