Game Development Reference
In-Depth Information
The rocket sprite
Time to tackle the second object in the game: the rocket.
Once again, I already put in place the part of the logic that's old news to you. But please re-
view the code already inside Rocket.cpp . We have a method to reset the rocket every
time a new game starts ( reset ), and a method to show the selected state of the rocket
( select(bool flag) ) by changing its displayed texture:
if (flag) {
this->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("rocket_on.png"));
} else {
this->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("rocket.png"));
}
This will either show the rocket with a glow around it, or not.
And finally a method to check collision with the sides of the screen ( col-
lidedWithSides ). If there is a collision, we adjust the rocket so it moves away from
the screen side it collided with, and we release it from any pivot point.
What we really need to worry about here is the rocket's update method. And that's what
we'll add next.
Search WWH ::




Custom Search