Identify and link ID of randomly spawned objects

Get help using Construct 2

Post » Mon Feb 27, 2012 12:01 pm

Hello!

I don't know if the title fits to what I'd like to learn. I really need your help because I'm stuck with something that should work and I start getting crazy...

Here is the gameplay loop of my game (it is a old test version -but fonctional- but you'll be able to figure out what the game is about and what I'd like to do).

http://dl.dropbox.com/u/63083711/index.html

The physical objets I mentioned are randomly generated from the bottom of the screen, every X frames. In the example above, they are not animated and... I want them to be animated and keep their circle collision.

Ashley recommended me to spawn a physical object (invisible) using the collision and put the animated sprite over it (creating the illusion that the animated sprite itself has the circle collision).

So everytime I spawn a physical objet, I need to link to it its visual aspect. In theory, nothing really complicated but I can't make it work even if that's what I did with the dropped balls. This time I must have done something wrong and I get too angry to see what...

- First, I create the physical objet. I give it an ID (taken from a enemy counter, a global variable called IDEnemy01Count, increased each time a new enemy is spawned in order to make it unique... I could use the IID but it doesn't work either, I suppose the problem doesn't come from there).

- Then I spawn on it the visual aspect. I give it an ID, the same than the physical objet, in order to create a link between both.

- and... it's a mess: the very first spawned object and its visual aspect move as they should do, and once the second physical objet is spawned, all the visual aspects just... stop and don't follow the physical objects.

Here is the code I use:







As I said, that's how I proceed with the dropped balls (it's a physical objet with a visual aspect over it), but I don't know why... in this case, it worked :o

Seriously, that's something that made me crazy for hours recently, I may have missed something obvious, simple and stupid... but maybe I just don't know how to identity an objet among other similar, after having spawned them "generically". If I could master that kind of things, everything would be easier...

Thanks in advance.

Rag'


PS: I may be unclear in my explanations... If so, please don't hesitate to ask questions in order to identify what's wrong. I really need to make it work
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Mon Feb 27, 2012 12:09 pm

Maybe you could share the CAPX of the project that you have troubles with...
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Mon Feb 27, 2012 12:27 pm

You're right, here is the .capx:

http://dl.dropbox.com/u/63083711/MagicBalls%200.212.capx

(the physical objet is not set to invisible, in order to perform some tests...)

Ragtime2012-02-27 12:33:11
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Mon Feb 27, 2012 5:38 pm

In the event 242 (movement of visual aspect), add one condition: "For each Enemy01".

Without this condition Enemy01 represents all matching instances, and in this case I'm not sure what Enemy01.ID represents.
The subevent is then run only one time, with Enemy01 being all matching instances.
Well I'm new to construct so I'm not sure what happen exactly in this case.

All I know is that with ForEach you run the following subevent one time for every matching Enemy01, and that's what you want :)yumyum2012-02-27 17:50:08
B
15
S
7
G
1
Posts: 10
Reputation: 1,445

Post » Mon Feb 27, 2012 7:47 pm

yumyum, dear pink bear... YOU'RE MY HERO!

I didn't even know that the ForEach action existed and that's EXACTLY what I needed, as you said. It was a torture to identify a specific instance without this and...

... now it works like a charm!! THANK YOU!!! I'll apply this on different part of my project, in order to clean it
B
17
S
4
G
4
Posts: 137
Reputation: 3,767


Return to How do I....?

Who is online

Users browsing this forum: makkancs, Matthew de and 38 guests