Animation in libgdx

I am wondering if there is an easy way to animate in libgdx. I am thinking of an API where I can just specify the duration and final location of the texture (as in the Flash Tween library).

I searched on google and the closest I got is the Animation class, which I think requires libgdx, requires the user to specify a texture for each keyframe.

new Animation(0.5f, texture1, texture2, texture3); 
+4
source share
3 answers

You can use TextureRegion # split (texture, tileWidth, tileHeight) to get a bunch of texture areas for the texture, if they are laid out in a grid. You can also use TexturePacker on a bunch of lost images to pack them into a single texture and then load from TextureAtlas. This has the advantage that it can remove spaces from each frame for better packaging, and it can also do fantastic things such as anti-aliasing (if two frames are identical, it will be packed only once). Name your frame images such as anim_1.png, anim_2.png, etc., and then you can get all the texture areas with the name "anim" as an ordered list based on the frame number.

Also note that the Animation class in libgdx is simplified. Feel free to write yourself if this does not meet your needs. The animation class is only about 20 lines of code.

+11
source

It depends on what kind of animation you want. If this is an animation based on different images, then yes, you should use an animation class with different texture areas. However, if you need an animation based on motion interpolation, you should use an animation library, such as in Flash.

Libgdx has a built-in Interpolator helper that allows you to create simple interpolation with attenuation. If you want a full tweening engine like Flash, take a look at the java Universal Tween Engine .

+2
source

Animation in libgdx is simple. I use Array textures or textureregion in the Animation parameter instead of putting a lot of textures or textureregions. And after I declare, I set the animation playback mode like this:> animation.setPlayMode(Animation.PlayMode.LOOP); it works. I draw the animation using the variable float runTime, which is set like this runTime + = delta or runTime = runTime + delta --> spriteBatch.draw(animation.getKeyFrame(runTime), x, y, width, height);

0
source

All Articles