Load idle animation when nothing key pressed

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Load idle animation when nothing key pressed

Postby quangtran » Sun Jan 28, 2018 6:33 am

I can move a player forward/backward with animation walking with left/right key but I want when nothing key pressed an idle animation must load to player instead of animation walking. I capture event the keyup but not ok, it began to messy.

Thank you for reading.

Code: Select all
public void create () {

      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();
      batch = new SpriteBatch();   
      playerAtlas = new TextureAtlas(Gdx.files.internal("idle.atlas"));
      playerAnimation =new Animation(1/1.0f,playerAtlas.getRegions());   
                currentAnimation = playerAnimation;      
      Gdx.input.setInputProcessor(this);
}

public void render () {

      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      batch.begin();
      elapsedTime += Gdx.graphics.getDeltaTime();
      batch.draw(currentAnimation.getKeyFrame(elapsedTime,true),posX,100);
      batch.end();
}
Last edited by quangtran on Sun Jan 28, 2018 6:09 pm, edited 6 times in total.
quangtran
 
Posts: 2
Joined: Sun Jan 28, 2018 6:01 am

Re: how to start and stop animation

Postby evilentity » Sun Jan 28, 2018 9:44 am

Frame you get depends on time you pass in, if you dont change it, you will get the same frame.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4427
Joined: Wed Aug 24, 2011 11:37 am


Return to General Development

Who is online

Users browsing this forum: Raith and 1 guest