How do I pick top instance for scoring

Get help using Construct 2

Post » Wed Oct 19, 2016 10:01 pm

"The Image"
Disks are created with stars for each disk. Since the disks are created at different times on that layer, they overlap each other - each new instance is created above the last instance.

Image

If the ball is 'overlapping' or 'on collision' with a star it's destroyed and scored (I've tried both ways). The problem is if there are other stars directly below the one the ball is currently on, all stars underneath are destroyed and scored.

How can i destroy and score only the star that is on the disk that the ball is currently on? I've thought about trying it as scoring a 'combo', when 2 or more stars are directly underneath, but that's way beyond my brain.

I've tried different ways that @99Instances2Go solved for me in the capx of this thread: https://www.scirra.com/forum/viewtopic.php?t=183022 which include a 'pick top instance' sub-event, but still can't figure this one out.


Thanks for any help or input.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Wed Oct 19, 2016 10:42 pm

Cant use containers, because killing the star would kill the disk.

Give the star an instance variable 'parent'.
When you create the disk and the star ... set star.parent to disk.UID

Give the star an instance boolean 'selected'

Now
In the event where you pick the disk that is overlapping the ball and refine that to the top most disk ...

Add a 'every tick'
with the action ... star > set boolean 'selected' to false

add the following condition ..
star > pick by UID .. UID = disk.UID
and the action ... star > set booelan 'selected' to true

Now you can pick the right ball anywhere in your events with ...
star is overlapping ball
star has boolean 'selected' set

Question ... why is this not working ?
star is overlapping ball
star is top most
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Oct 19, 2016 11:05 pm

@99Instances2Go

Holy crack, braniac! Uhhhhh.....thanks for the reply.

Gonna have to go over that a few times for it to sink in.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 42 guests