Im trying to code a tile based platformer game with slick2d. While handling the collisions, Im facing with this problem. I could fix it for only that situation but I guess there must be a better way.
The problem is for example when the player is moving around the X axis, animation moving right or moving left starts to animate. And i draw a rectangle for the bounds of the animation. When it starts to move around Y axis, the animation changes, and the side lenghts of the rectanle also changes. And the animation stucks with the blocked tiles. See the Images below:
](character and movingLeft/Right are animations)
// Moving the character
if (input.isKeyDown(Input.KEY_UP)) {
velocityY = -speed;
character = frontView;
}
else if (input.isKeyDown(Input.KEY_DOWN)) {
velocityY = speed;
character = frontView;
}
else {
velocityY = 0;
}
characterPositionY += velocityY;
character.setMesh();
if(collidesWith(character.animationMesh)){
characterPositionY -= velocityY;
velocityY = 0;
}
if (input.isKeyDown(Input.KEY_LEFT)) {
velocityX = -speed;
character = movingLeft;
}
else if (input.isKeyDown(Input.KEY_RIGHT)) {
velocityX = +speed;
character = movingRight;
}
else {
velocityX = 0;
}
characterPositionX += velocityX;
character.setMesh();
if(collidesWith(character.animationMesh)){
characterPositionX -= velocityX;
velocityX = 0;
}
y=unit.position.y
Switch to this:y=window.size.height - unit.position.y + unit.size.height
. – sakul_ca Mar 13 at 2:31