0
\$\begingroup\$

I have a Player Class and i have 3 different Animations for it. I can render them perfectly but i don't know how to change from one animation to another. For exmaple i have 3 animations, one for Running, one for Jumping and one for Rolling down. Now i want to to change from running animatioon to Jumping when user presses a button. Inpout is not the problem. I am using the same code at LibGDX wiki to create to sue animation just like in this link: https://github.com/libgdx/libgdx/wiki/2D-Animation

It would be very helpful if you could give an example too but its not necessary though.

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

An animation is just a group of frames which are drawn sequentially. If you were able to render one animation, to change it you just have to change the frames.

That example splits a Texture into TextureRegions by splitting it in a grid, I recomment you create a TextureAtlas instead, its easier to access the different TextureRegions in it.

To change the Animation, you just create a new instance of Animation with a different set of frames. That is really just it.

\$\endgroup\$
0
\$\begingroup\$

Well, just a simple way to do it, in your player class create the 3 textures for each animation if you're not using a TextureAtlas, then use a int playerState to specify the state of the player (1 for running, 2 for jump, 3 rolling down),and finally in the draw method use a bool to check playerState and draw each animation.

\$\endgroup\$
0
\$\begingroup\$

I have to agree with Xkynar on this, but I'd like to add something. In order to keep track of the different animations, you can use the libGDX Hashmap in order to store each Animation object under a string name, like "running" ,"walking", or whatever. Each animation can then be accessed by requesting the name of the animation in the Hashmap. If you'd like more information I can probably find an example somewhere.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .