Game Development Reference
In-Depth Information
if (_floating) {
_floatingTimer += dt;
if (_floatingTimer > _floatingTimerMax) {
_floatingTimer = 0;
this->setFloating(false);
}
}
}
When the player presses the screen for a jump, we shouldn't make the sprite jump
immediately. Changes in state should always happen smoothly. So we have a
boolean
property in
_player
called
_jumping
. It is set to
true
when the
player presses the screen and we slowly add the jump force to
_vector.y
. So
the longer the player presses the screen, the higher the jump will be and a quick
tap will result in a shorter jump. This is a nice feature to add to any platform
game.
We next limit the
y
speed with a terminal velocity, update the next position of the
_player
object, and update the floating timer if
_player
is floating.