How do I spawn an object and change its animation

Get help using Construct 2

Post » Tue Nov 07, 2017 11:58 pm

I'm working on a level editor, and when placing enemies I have it set to spawn a sprite on the object in the editor menu, but here's the catch. I'm trying to get away with using just one sprite object, and using different animations to represent different objects/enemies. To identify which object is which, I assigned a variable with a number to correspond with each object preview animation. However, when I try to spawn the second kind of object (a snail enemy), it spawns the object, but with the first object animation (a slime enemy). In the debug, it shows that the newly spawned object (the one placeable in the editor) won't spawn with the proper variable (it's at 0 when I want it to spawn as 1, so it will switch to the second animation).

Pls help
B
12
S
4
Posts: 53
Reputation: 1,223

Post » Wed Nov 08, 2017 1:35 am

Are you assigning any value to that instance variable after you spawn a new instance of the sprite?
You need to specifically assign the proper value, unless you want it to be default. I'm guessing your default value is 'slime'.
Same applies to the animation.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
71
Posts: 1,081
Reputation: 38,725

Post » Wed Nov 08, 2017 3:38 am

dop2000 wrote:Are you assigning any value to that instance variable after you spawn a new instance of the sprite?
You need to specifically assign the proper value, unless you want it to be default. I'm guessing your default value is 'slime'.
Same applies to the animation.


I had it set as a number, 0 for slime, 1 for snail. The problem was that the newly spawned enemy wasn't setting it's variable to 1 and changing its skin. I ended up doing separate sprites. anyways. I reckon it'll be better in the long run.
B
12
S
4
Posts: 53
Reputation: 1,223

Post » Wed Nov 08, 2017 4:59 am

Did you set the value 0/1 with events? You were doing something wrong, because a code like this should definitely work:
Code: Select all
 
.... Spawn Enemy
     Enemy Set enemyType=1
     Enemy Set animation to "Snail"
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
71
Posts: 1,081
Reputation: 38,725


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests