Spawning a random object from an array

  • Hi guys,

    I want to make an enemy, when it dies, destroys itself and spawn another random object, which is going to be his death animation. I'm doing it currently with one death animation, and this is the only way that it comes to my mind that it could be done "easily".

    It has to be a must to destroy the enemy, as if it doesn't my code won't work, as he would respawn and then, he'll be invincible.

    So.. basically, I wanted to create an array, loaded with enemy01 death animations, and when enemy01 dies, it would spawn a random object animation from that array.

    Is this possible to do?

    Would anyone lend me a hand in doing so?

    Thanks in advance,

    Miyavi.

  • You don't really need an array for that, just use an object with several animations:

    Example: RandomDeathAnimation.capx (r96)

  • I thought of that, but as every enemy has plenty of code with it, when it dies, and play that animation, something weird will happen, as it will act as if he was actually alive, and reset his animation when I enter/leave his "active zone". (I'm currently working on this with a "dead" variable, as I didn't need it before, as the object would be destroyed when dead.)

  • The enemy is destroyed when dead in my example.

  • Hum, got it. I'm currently downloading r96, to look it up.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah, sorry I meant to make it in r95 as there is a nasty include bug in r96. My mistake, give me a shout if you want a r95 version instead.

    What I did was just create a new "Enemy dead" object and use a random expression for the animation. Nothing fancy.

  • Hmm..seems pretty neat.

    That's right because you're spawning another object, so it does not have the same properties/variables (lives, points, solid..) as the original one would have, which was my main problem.

    I think this should work, so thanks for that.

    I'll try to implement that in a sec.

  • Well, I implemented that, but don't know why, the random doesn't seems to be working, as it always spawns the same anymation.

  • Nevermind.. it seems to work now. Maybe it was just bad RNG. :P

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)