Jump to content

Overwrite sprite animation for different enemy types in sprites group..?


BdR
 Share

Recommended Posts

I have a group of enemy sprites, this is a pool of sprites that is recycled by kill() and revive(). They are reused, so at one point it may be enemy type A which is killed and then that same sprite is revived but now it is enemy of type B. This is done by setting the animation at the moment of reviving an enemy. So I use the same animation name every time and I assume it is overwritten, in other words the old animation of the previous enemy is not kept in memory. Is that correct?
 
My github example project is updated with crudely animated sprites (it's just an example), see updated github source here:
 
This is the part of the code that creates or revives an enemy sprite:
function createAnimal(antype) {    ..    // get inactive animal from animals object pool    var animal = this.animalsGroup.getFirstDead();    // if there aren't any available, create a new one    if (animal === null) {        animal = new Animal(game, x, y, antype);        this.animalsGroup.add(animal);    };    animal.animations.add('myanimation', [ antype, antype+5, antype+10, antype+5], 8, true);    animal.play('myanimation', 5, true, false); // fps=5, loop=true, killOnComplete=false    // else revive the animal (set it's alive property to true)    animal.revive();    animal.x = x;    animal.y = y;    //etc.

So my question is, can I reuse sprites and overwrite their animation every time it is revived, without any problems? I mean, it *seems* to work but won't there in the long run be some sort of memory leak?

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...