Collision between two instances of the same sprite

Get help using Construct 2

Post » Tue Jan 08, 2013 7:05 am

Hey folks, my question might end up being one of those easy things that's just difficult to figure out how to search.

I have multiple instances of a sprite with an instance variable called "Value," which is a different number for every instance. I want to make it so that when two instances of the same sprite collide, I add their values together and store it in a variable.

How do I differentiate between the two instances of the same sprite in the "is overlapping" event? If it were two different sprites, it would be Sprite1.Value + Sprite2.Value in the resulting action, but if they are both instances of Sprite1, how do I get the value from each? (Sprite1.Value + Sprite1.Value doesn't work)

I'd know how to do this if it were two different sprites colliding or if I were scripting it traditionally, but I'm stumped here.

Let me know if you can help, thanks!
B
9
S
2
Posts: 87
Reputation: 1,051

Post » Tue Jan 08, 2013 4:50 pm

For a bit more clarification of what I mean, here's a screenshot of some debugging. The text set for Sprite0.Value is inconsistent on which instance it's pulling the variable from (sometimes it's the sprite being dragged, sometimes it's the one collided with).

Is there a way to differentiate between these two instances in the Event sheet so that I can get both of their values?

B
9
S
2
Posts: 87
Reputation: 1,051

Post » Tue Jan 08, 2013 5:54 pm

You can use the 'System: Pick nth instance' conditions to pick the individual sprites involved in the collision.

[code]
+Sprite0: On collision with Sprite0
   -> Text2: Set text to "0"
   +System: Pick Sprite0 instance 0
      -> Text2: Set text to int(self.Text) + Sprite0.value
   +System: Pick Sprite0 instance 1
      -> Text2: Set text to int(self.Text) + Sprite0.value
[/code]
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests