How do I spawn an object and change its animation

0 favourites
  • 4 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Did you set the value 0/1 with events? You were doing something wrong, because a code like this should definitely work:

     
    .... Spawn Enemy
         Enemy Set enemyType=1
         Enemy Set animation to "Snail"
    [/code:dhk0rxs7]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)