Thursday, 5 September 2013

how to make flying bird animation?

how to make flying bird animation?

I am new to libgdx and I am developing a simple game.The bird fly's from
one tree to other tree when tree is clicked.Now I was struck ed at flying
animation of bird please help me for solving this problem.There is single
image in rbird.pack which is 150*40 pixels containing 4 frames in it Here
is the code
public show()
{
.......
TextureAtlas atlas = new
TextureAtlas(Gdx.files.internal("gfx/ui/rbird.pack"));
flyingLeft = atlas.findRegion("bird1");
flyingRight = new TextureRegion(flyingLeft);
flyingRight.flip(true, false);
TextureRegion[] flyingLeftFrames = new TextureRegion[5];
for (int i = 0; i < 5; i++) {
flyingLeftFrames[i] = atlas.findRegion("bird1" + (i + 2));
}
flyingLeftAnimation = new
Animation(FLYING_FRAME_DURATION,flyingLeftFrames);
stateTime = 0f;
TextureRegion[] flyingRightFrames = new TextureRegion[5];
for (int i = 0; i < 5; i++) {
flyingRightFrames[i] = new TextureRegion(flyingLeftFrames[i]);
flyingRightFrames[i].flip(true, false);
}
flyingRightAnimation = new
Animation(FLYING_FRAME_DURATION,flyingRightFrames);
}
......
public render(float delta)
{
.....
//bird
stateTime += Gdx.graphics.getDeltaTime();
flyingmotion = flyingLeftAnimation.getKeyFrame(stateTime, false);
tree1.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x,float y)
{
if(isBirdOntree2() == true)
{
setBirdOntree2(false);
batch.draw(flyingmotion, 25, 40);
BirdOntree1();
setBirdOntree1(true);
}
}
});

No comments:

Post a Comment