Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.


Postby dermetfan » Wed Jul 10, 2013 2:24 pm

Maybe you forgot, but I mentioned this already.
dermetfan wrote:If you want to save as much memory as possible, you could even go one step furter and create one AnimatedSprite for all enemies. Because each enemy updates the Animation when drawing by default, the Animation is played 5000 times faster, so you have to update it manually. That's a good way if it's ok to have the same animation state for every enemy.
Code: Select all
// create one AnimatedSprite for all enemies
Animation animation = new Animation(1 / 3f, new TextureRegion(frame1), new TextureRegion(frame2), new TextureRegion(frame3));
animatedSprite = new AnimatedSprite(animation);

// set the one animation to all the enemies

// update the AnimatedSprite for all the enemies
public void render(float delta) {

It looks like you modified my example code (because of type2AnimatedSprite). Don't forget that there were these lines in it:
Code: Select all
type2AnimatedSprite.setAutoUpdate(false); // in show()
type2AnimatedSprite.update(delta); // in render()

If you know how many enemies you'll have and their number won't change, you could also set a frame duration that is the according time slower. I wouldn't usually recommend this, though.
For example, if you have and always will have 300 enemies and the frame duration should be a third of a second, you could set it to 1 / 3f * 300. This means you have to update 300 times to get past the same duration, which the 300 enemies will do for you, because each enemy updates the AnimatedSprite once individually.
Code: Select all
Animation animation = new Animation(frameDuration * numberOfEnemies, frame1, frame2, frame3);
AnimatedSprite animatedSprite = new AnimatedSprite(animation);
enemy1 = new Enemy(animatedSprite);
// ...
enemy300 = new Enemy(animatedSprite);
Posts: 408
Joined: Fri May 03, 2013 8:57 pm


Postby xeoshow » Wed Jul 10, 2013 2:43 pm

Hi dermetfan,

Sorry that I missed out the related info regarding bold words! Finally I decided to follow way 2, which is recommended by you. It is convenient and the memory consumption is small.

Thanks so much for your patience and really appreciate all your nice help!!
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am


Postby mmachida » Thu Mar 26, 2015 1:52 am

@dermetfan, is possible use your AnimatedSprite to animate ?
Last edited by mmachida on Thu May 28, 2015 8:35 pm, edited 1 time in total.
Posts: 142
Joined: Tue Mar 25, 2014 8:26 pm


Postby dermetfan » Sat Mar 28, 2015 2:45 pm

No, you need a 3D model, sound effects and NVIDIA PhysX to animate the player.

Ok. Honestly. Yes, yes it is possible. No offense. I promise.
Posts: 408
Joined: Fri May 03, 2013 8:57 pm


Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 2 guests