Cocos2d-x 3.0final Terminator Series Tutorial 09-Lacquer Node Middle schedule

Source: Internet
Author: User

How to do HelloWorld project HelloWorld text to achieve its own active movement?

Some children's shoes will think of using threads. Constantly changing the position of the label,

Do not do that because the cocos2d-x can only be changed by node information in the main thread. This is all because of node. Let's say we removed node from our scene.

Errors may be referenced in the child thread type. So, to make node run a specific change, you need to use schedule in the current node

Very easy to use

1. Add a method to the current HelloWorldScne.h in the Helloworldscene

Such as:

void Gamelogic (float t); Note that the number of references here is set to float

2. Add the following code to the Helloworldscene::init method:

This->schedule (Schedule_select (helloworldscene::gamelogic), 0.5);

and set a tag on the label.

Label->settag (110);


3. Implement this approach in HelloWorldScne.cpp

void Helloworldscene::gamelogic (float t) {

Change the coordinates of the corresponding label here HelloWorld

Auto Thelabel=this->getchildbytag (110);

Thelabel->runaction (Moveby::create (5,0.5));

if (Thelable->getpositionx () >480) {Thelabel->setpositionx (0);}

}

This achieves the HelloWorld's own initiative to move to the right, moving 5 pixels every 0.5 seconds.

Runaction is used here, and actually directly through Thelabel->setpositionx (NEWX), we can change the various properties of node here to achieve the role of node transformation in the scene.

The action is a node conversion package, which is described in the following sections.


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Cocos2d-x 3.0final Terminator Series Tutorial 09-Lacquer Node Middle schedule

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.