Understanding actions
We can easily tell our sprites to perform concrete actions, such as jump, move, skew, and so on. It requires a few lines to get our sprites to execute the desired action.
Moving sprites
We can make our sprite move to a specific area of the screen by creating a MoveTo
action and then making the sprite execute the action.
In the following code listing, we are making the bomb fall to the bottom of the screen by simply writing the following code lines:
auto moveTo = MoveTo::create(2, Vec2(sprBomb->getPositionX(), 0 - sprBomb->getContentSize().height/2)); sprBomb->runAction(moveTo);
We have created a moveTo
node that will move the bomb sprite to the current horizontal position, but it will also move it to the bottom of the screen until it is not visible. In order to achieve this, we made it move to the y position of the negative half of the height of the sprite. Since the anchor point is set to the center point of the sprite, moving it to the negative half of its...