Question

I am building a mobile game and trying to implement the same concept of image rotation as Flappy bird.

I am able to rotate the image counter clock with gravity and when I touch the screen the rotation is clockwise

My issue is that I am not getting a smooth rotation clockwise when I touch the screen to make the bird fly. The bird looks like it rocking like a boat. I know it has to do with the origin but I am stuck here.

See my code

private void updateAnimation(){
    stateTime += Gdx.graphics.getDeltaTime();                      


    if(!Play.hit && Play.state != Play.GAME_OVER)
       currentFrame = walkAnimation.getKeyFrame(stateTime, true); 


     anim = new Sprite(currentFrame);
     anim.setSize(BODY_WIDTH, BODY_HEIGHT);
     anim.setOrigin(BODY_WIDTH/2, BODY_HEIGHT/2);
     anim.setPosition(SCREEN_X-BODY_WIDTH/2, Player.position.y);

     if(Play.state == Play.GAME_RUNNING ){
         if(ANGLE >= -75){

            if(!Gdx.input.justTouched()){
                updateRotation();
            }

         }

         anim.setRotation(getANGLE());
     } 

     anim.draw(batch); 
}

public void  updateRotation(){
    ANGLE = Player.velocity.y / 8;
}

this is the code for setting the rotation clockwise

if(GameWorld.ANGLE <= 10){
    GameWorld.setANGLE(5* Gdx.graphics.getDeltaTime());
}
Player.velocity.y = 320;
Was it helpful?

Solution

Rotating the Texture region instead via the batch

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top