Game Development Reference
In-Depth Information
Time for action - coding the player
Open up the Player.cpp class.
1. The _player object is created through a static method that uses our blank.png
file to texture the sprite. That method also makes a call to initPlayer , 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 re-
quirements.
2. Next comes setFloating :
void Player::setFloating (bool value) {
if (_floating == value) return;
if (value && _hasFloated) return;
_floating = value;
if (value) {
_hasFloated = true;
_vector.y += PLAYER_JUMP * 0.5f;
}
}
Search WWH ::




Custom Search