Lioman
Lioman

Reputation: 535

Switch scene after end of sequence

I've got an cocos2d-x javascript project with a "splash screen" scene (logos etc). After the end of the last sequence I want to switch automatically to the next scene.

How is this possible? Can I add something to the sequence? Or how do I use isDone() to check when I have to call cc.director.runScene(new mySecondScene()).

Upvotes: 1

Views: 141

Answers (1)

Роман Гуйван
Роман Гуйван

Reputation: 1128

Well you can add another action to your sequence (an instant action). This fits the purpose perfectly

http://www.cocos2d-x.org/docs/api-ref/js/v3x/symbols/cc.CallFunc.html Using the code you've provided in the post:

function nextScene(){
  cc.director.runScene(new mySecondScene());
}

var switchToTheNextScene= new cc.CallFunc(nextScene, this);
var sequence2 = new cc.Sequence(sequence, switchToTheNextScene);
someNode.runAction(sequence2);

Also, an off-topic advice - you can wrap the scene in a cc.TransitionScene subclass to make your splashscreen disappear in a cool way. No sequences are included Something like:

    cc.director.runScene(cc.TransitionFade(0.8, new mySecondScene()) );

Where 0.8 is the transition time. Again, check the docs for cc.TransitionScene subclasses, cocos 2d js has a lot of them

Upvotes: 1

Related Questions