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