differents images for differents instance of a unique object

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi

    I try to make that :

    • I have an object named "enemy"
    • at the layout I create several instance of this object "enemy", with different vprivate variable (nammed "type").
    • with each value (for the variable private "type"), I want to load somes images (to have differents enemys, but with a unique object). So to have differents instances of the same object which dras diffirents images (animation).

    I have try with several animations, sub-animations, etc.. But, it doesn't work. I don't know why.

    http://blendman.free.fr/construct/enemyImages.zip

    Someone knows what I'm doing wrong ?

    Thank you

  • Hate to say it, but there's a lot wrong with your CAP. First, we'll start off with the main problem.

    First we'll take a look at this chunk:

    <img src="http://dl.dropbox.com/u/917406/foreach.png">

    These "For each" loops are unnecessary and messing up the picking. Instead of only picking the most recently created object, it's looping through each object created up to now and performing actions on it. This means that whatever happens to the last object you create will happen to all of your objects. To fix this, just take the actions from the "For each" loops and place them in the "Repeat" loop, then put the sub-events to the second "For each" loop as a subevent to the "Repeat" loop and get rid of the "For each" loops, like this:

    <img src="http://dl.dropbox.com/u/917406/noforeach.png">

    Also, the int() cast when generating a random number is unnecessary and seems to be messing things up. And since you only have four objects, the expression should be this: 1 + random(4)

    Next up, we have this chunk:

    <img src="http://dl.dropbox.com/u/917406/else.png">

    These else conditions are unnecessary and messing things up due to issues with the else condition. The checks to see which animation is playing are also unnecessary, as are the actions to tell the current animation to play. An animation automatically starts playing when you switch, so they're not needed. This chunk should look more like this:

    <img src="http://dl.dropbox.com/u/917406/noelse.png">

    And that should get it working. Not only will this fix the problems, but you'll also get cleaner code, which is always a good thing.

    Here's a download for the modified CAP.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, many ways to do this. Here's yet another:

    http://dl.dropbox.com/u/666516/data.zip

  • Linkman2004 : Thank you for your answer. And sorry for my example. itwas very bad when I re open it. Thank to you I have understand how does work the repeat and for each object event.

    Thank you for the example.

    Newt : thank you for helping me. Your example is very interesting too. It reminde me some GML code. Thanks !

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