Add the code in the last scene switch and a picture in res as a picture in the first scene
HelloWorldScene.cpp in the
BOOL Helloworld::init ()
{
//////////////////////////////
1. Super Init first
if (! Layer::init ())
{
return false;
}
/**
* The following code implements the purpose of switching scenes,
* When clicking on the font in the text box, toggle the scene, there are pictures
*/
Get the size of the visible area
Size visiblesize = director::getinstance ()->getvisiblesize ();
Add a picture in the first scene to be able to see the effect when the scene transitions
Sprite *BG = sprite::create ("bird.jpg");
Bg->setposition (Point (VISIBLESIZE.WIDTH/2, VISIBLESIZE.HEIGHT/2));
AddChild (BG);
Add text box, text content, font type, font size
Labelttf *label = Labelttf::create ("Show Next Scene", "Courier", 36);
AddChild (label);//Add text to the layer
Put text in the middle
Label->setposition (VISIBLESIZE.WIDTH/2, VISIBLESIZE.HEIGHT/2);
Set up event listeners for label
1. Creating listeners
Eventlistenertouchonebyone *listener = Eventlistenertouchonebyone::create ();
2. Let Listener->ontouchbegan point to a closure function to execute
[Capture label Variable]
Listener->ontouchbegan = [Label] (Touch *t, Event *e) {
Judge the,label-> boundary. Includes (touch point), indicating that the click is a label, then a new scene is executed
if (Label->getboundingbox (). Containspoint (T->getlocation ())) {
Run the newly created scene
Director::getinstance ()->replacescene (Imagescene::createscene ());
Set the effect of scene transitions and the scene disappears after 1 seconds
Director::getinstance ()->replacescene (transitionfadebl::create (1, Imagescene::createscene ()));
}
return false;
};
3. Adding event listeners
Parameters (Listener, node is the node to listen on)
Director::getinstance ()->geteventdispatcher ()->addeventlistenerwithscenegraphpriority (listener, label);
return true;
}
Effects of scene transitions