differents images for differents instance of a unique object

For questions about using Classic.

Post » Sat May 15, 2010 2:18 pm

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 :)
B
2
S
1
G
2
Posts: 23
Reputation: 846

Post » Sat May 15, 2010 3:02 pm

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

First we'll take a look at this chunk:



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:



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:



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:



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.
Moderator
B
97
S
36
G
19
Posts: 1,584
Reputation: 17,692

Post » Sat May 15, 2010 3:46 pm

Yes, many ways to do this. Here's yet another:
[url:1qm2rzzt]http://dl.dropbox.com/u/666516/data.zip[/url:1qm2rzzt]
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue May 18, 2010 12:47 pm

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 !
B
2
S
1
G
2
Posts: 23
Reputation: 846


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests