Spawning a random object from an array

Get help using Construct 2

Post » Wed Jun 27, 2012 8:32 pm

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.
B
6
Posts: 54
Reputation: 808

Post » Wed Jun 27, 2012 8:58 pm

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

Example: RandomDeathAnimation.capx (r96)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jun 27, 2012 9:02 pm

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.)
B
6
Posts: 54
Reputation: 808

Post » Wed Jun 27, 2012 9:05 pm

The enemy is destroyed when dead in my example.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jun 27, 2012 9:07 pm

Hum, got it. I'm currently downloading r96, to look it up.
B
6
Posts: 54
Reputation: 808

Post » Wed Jun 27, 2012 9:08 pm

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.Nimtrix2012-06-27 21:09:12
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jun 27, 2012 9:13 pm

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.
B
6
Posts: 54
Reputation: 808

Post » Wed Jun 27, 2012 9:41 pm

Well, I implemented that, but don't know why, the random doesn't seems to be working, as it always spawns the same anymation.
B
6
Posts: 54
Reputation: 808

Post » Wed Jun 27, 2012 9:46 pm

Nevermind.. it seems to work now. Maybe it was just bad RNG. :P
B
6
Posts: 54
Reputation: 808


Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, ManuelPerez and 21 guests