Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

enter image description here ](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;
    }
share|improve this question
    
Looks like you just need to swap the y position for rendering your character. for rendering if you are doing this: y=unit.position.y Switch to this: y=window.size.height - unit.position.y + unit.size.height. – sakul_ca Mar 13 at 2:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.