I have done a map with Tiled. Every single tile of it measures 32x32 px
so does my main character sprite.
In my class Player.cpp
, I have some functions that calculates a deltaY/X
which decide if you are going Left/Right/Up/Down
and then you use them in the update function.
That's my code so far:
void Player::moveX(int moveDirection) {
deltaX = moveDirection * PlayerConstants::WALK_SPEED;
playAnimation(deltaX > 0 ? "WalkRight" : "WalkLeft");
facing = deltaX > 0 ? DIRECTION ::RIGHT : DIRECTION::LEFT;
}
void Player::moveY(int moveDirection) {
deltaY = moveDirection * PlayerConstants::WALK_SPEED;
playAnimation(deltaY < 0 ? "WalkUp" : "WalkDown");
facing = deltaY < 0 ? DIRECTION ::UP : DIRECTION::DOWN;
}
void Player::update(float elapsedTime) {
_x += deltaX * elapsedTime;
_y += deltaY * elapsedTime;
AnimatedSprite::update(elapsedTime);
}
Walk Speed is 0.1
right now.
Any guesses on how to move it tile by tile?