Realtime Instance Grouping

Discussion and feedback on Construct 2

Post » Sun Jan 19, 2014 1:12 am

So I've run into this problem with various projects, and before I make an complicated an bulky solution I'd like to know if anyone has found a simpler way. A lot of object have events that apply to all instances of that object. For example, if I have a physics ragdoll, copy that ragdoll, the physics will be shared between both instances of the ragdoll. I need to figure out a way that allows me to use the same object types and to treat each group of specified objects as it's own instance. If I'm not making sense let me know, does anyone have an idea to do this?
B
71
S
24
G
11
Posts: 452
Reputation: 12,350

Post » Sun Jan 19, 2014 6:55 pm

You have to pick which object you're referencing to.

You can do this by creating an event "System -> Pick", or "Object -> Pick", there are a lot of options on there (such as pick nearest to something, pick nth instance, pick by UID, etc).
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Sun Jan 19, 2014 11:29 pm

[QUOTE=andreyin] You have to pick which object you're referencing to.

You can do this by creating an event "System -> Pick", or "Object -> Pick", there are a lot of options on there (such as pick nearest to something, pick nth instance, pick by UID, etc).[/QUOTE]

That sounds good on paper but I can't find a practical way to implement it. For example, I have three object types, when you shoot them, a particle is created that moves with that object. How would I pair the particles, notice that if you shoot the objects too fast the particle will apply to the wrong instance.

Demo

Project File
B
71
S
24
G
11
Posts: 452
Reputation: 12,350

Post » Mon Jan 20, 2014 6:24 am

Picking by Unique ID is the way I would do it in this case.

I Added an instance variable to Particles called Victim, and when the Particles object is created I store the Sprite.UID in the Victim variable so we now know the Sprite that the Particle object is associated with.

Then I added a loop in the Every Tick section, for each Particles, we pick the Sprite with UID = Particles.Victim, then set the Particles position to that Sprite's position.

I also randomly create new Sprite objects to shoot... :)
Oh, I also added Fade to Sprite and Particles, so that they fade out of existence - because the bodies were really starting to pile up, and the Particle instances were still active even after the rate was reduced to nothing.

you can get the file here: www.rieperts.com/games/forum/sniper.capxAllanR2014-01-20 07:36:27
B
98
S
34
G
20
Posts: 438
Reputation: 17,815

Post » Mon Jan 20, 2014 6:46 am

My son has been making games with enemies, and wanted a health bar over each one. So, when he places each enemy on the layout, he puts a health bar near it. Then at the start of the layout he loops through each enemy, picks the nearest health bar, and pins it to the enemy. And puts the health bar UID in an instance variable in the enemy, so when the enemy takes damage he knows which health bar to reduce.

That is another way to handle this type of problem...
B
98
S
34
G
20
Posts: 438
Reputation: 17,815

Post » Sun Jan 26, 2014 12:23 am

@AllanR

Thanks for all the feedback and advice! I'll try implementing it in my project when I get a chance.
B
71
S
24
G
11
Posts: 452
Reputation: 12,350


Return to Construct 2 General

Who is online

Users browsing this forum: Tombas and 12 guests