Interacting between different instances of an obj

For questions about using Classic.

Post » Sat Dec 24, 2011 6:48 pm

So, hi!

I have two objects, both of the same sprite/type, oPlanet.
When one overlaps each other, how can it make it so something happens to one of the sprites, and something ELSE to the other?
Like, if the first has X bigger than the second, how can I make it so X gets even bigger for the first, and Y smaller for the second, even though they're sprites of the same object?
I know, very confusing. Please help me if you understood anything.
B
1
G
1
Posts: 3
Reputation: 581

Post » Sat Dec 24, 2011 9:41 pm

lol couldn't tell ya. This has been a problem for me since I started making games. I've always wanted some sort of condition like so:

If (Object with value A) collides with (Object with value B) then do something with (Object with value A)

but I don't think it'll ever happen..can't really say why either, it seems pretty basic.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sat Dec 24, 2011 10:01 pm

put the object into a family.

on Object collides with Family
----Object do this
----Family do that
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Dec 24, 2011 10:12 pm

[QUOTE=Tokinsom] lol couldn't tell ya. This has been a problem for me since I started making games. I've always wanted some sort of condition like so:

If (Object with value A) collides with (Object with value B) then do something with (Object with value A)

but I don't think it'll ever happen..can't really say why either, it seems pretty basic.[/QUOTE]

Well, that already exists. Just use sub-events and private variables. For example, let's say there's a sprite with pv 'myID'. Three instances of that sprite exist. Their pvs are set to "red", "green" and "blue".

+ On collision between sprite and sprite (this will put both instances on the sol)
++ sprite: Value 'myID' equal to "red" (this sub-event will only select the instance with pv "red" if it is already on the sol)
++ sprite: Value 'myID' equal to "green" (same as above)
++ sprite: Value 'myID' equal to "blue" (same as above)

With such a construction any two (or all three) instances that collide, will react according to the sub-events. Of course, you could further narrow down with other conditions/sub-events. For example, 'for each' as a sub-event to the 'on collision'-event will loop only through the instances that are already on the sol (which are the instances that collided).
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Dec 24, 2011 10:25 pm

You can also use for each.
The collision will act as a filter, if you do the for each after the collision condition. You can then use loopindex to pick in actions.

+>Sprite on collision with sprite
->for each sprite sprite set value to loopindex

Then there's also picking by position(closest).
+>Sprite on collision with sprite
->sprite pick closest to 0,.y
-->pick closest to .x,0 do stuff
->sprite pick closest to layoutwidth,.y
-->pick closest to .x,layoutheight
That works since usually two object don't occupy the same xy on collision.

Edit:
Didn't read Tula's last para, so yeah what he said with loopindex for good measure.
newt2011-12-24 22:29:26
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests