Effects of scene transitions

Source: Internet
Author: User
Tags addchild

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.