Time for action – coding the player
Open up the Player.cpp
class.
The
_player
object is created through a static method that uses ourblank.png
file to texture the sprite. That method also makes a call toinitPlayer
, and this is what you should type for that method:void Player::initPlayer () { this->setAnchorPoint(Vec2(0.5f, 1.0f)); this->setPosition(Vec2(_screenSize.width * 0.2f, _nextPosition.y)); _height = 228; _width = 180; this->setTextureRect(Rect(0, 0, _width, _height)); this->setColor(Color3B(255,255,255)); }
The
_player
object will have its registration point at the top of the sprite. The reason behind this top center anchor point has much more to do with the way the_player
object will be animated when floating, than with any collision logic requirements.Next comes
setFloating
:void Player::setFloating (bool value) { if (_floating == value) return; if (value && _hasFloated) return; _floating = value; ...