How do I distinguish 2 instances of the same objects?

Get help using Construct 2

Post » Tue May 19, 2015 6:36 pm

I have 2 instances of one object - sprite "bouncingBall". I'd like to make a sparkle when they collide in the point that they collide. So i made:
Code: Select all
bouncingBall - on collision with bouncingBall:
  1. System - create object sparkle on layer 1 at abs(bouncingBall.x-bouncingBall.X),abs(bouncingBall.y-bouncingBall.y)

But it doean't work as C2 takes the same instance to position sparkle - that is of course logical, but how to make it to create object between those 2 instances of bouncingBall?
B
55
S
14
G
10
Posts: 287
Reputation: 7,677

Post » Tue May 19, 2015 7:30 pm

@tecbug

A) You can use the condition

Object Type -> Pick [...]

There are several conditions to pick a certain ball.
I think you should pick the balls by their unique ID

B) You can give them instance variables that work as an individual ID by which you can pick them. (Object Type -> Instance Variable ("MyID" = 1) --- Action: Place Sparkle on Object.X,Object.Y).

Checking for an instance variable automatically picks the entities for which these condition is true.
B
5
S
1
Posts: 33
Reputation: 462

Post » Tue May 19, 2015 7:42 pm

It's easier to use a family. Then you test ball - on collision with family, and you address each one.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue May 19, 2015 7:55 pm

Without families using pick nth instance should work also:

System -> Pick nth Instance

If 2 instances collide, picking instance 0 will pick the first instance and instance 1 will pick the 2nd instance

ON collision bouncingBall with bouncingball
Pick instance 0 ... do whatever
Pick instance 1 .. do whatever

if on pick instance 0 you set two variables to CollisionX = bouncingball.x, CollisionY = bouncingball.y

then on pick instance 1 you can use your code
> System - create object sparkle on layer 1 at abs(CollisionX-bouncingBall.X),abs(CollisionY-bouncingBall.y)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue May 19, 2015 8:43 pm

@LittleStain - thanks that's best solution.
B
55
S
14
G
10
Posts: 287
Reputation: 7,677


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 21 guests