Detecting if the same sprite is hit twice in a row

Get help using Construct 2

Post » Sun Jul 28, 2013 7:43 pm

Suppose I have 6 sprites on the screen and they are 2 sprites named "apple", 2 sprites named "orange" and 2 sprites named "cherry". If I have another sprite named "rock" and I drop it on the sprites below, is there a way to detect if it hit the same sprite twice in a row. It would have to reset if it hit an apple first and then an orange. If for example, it hit the orange first and then the other orange, it would do something like play a sound. Thanks much if you can say how.
B
19
S
8
G
3
Posts: 73
Reputation: 4,145

Post » Sun Jul 28, 2013 8:22 pm

Have a 'lastHit' global variable and set it to the object's name on collision with that object. Then you can say 'on collision with cherry + global variable = cherry: play sound'. Then as a sub-event 'set global variable to cherry'. Setting the variable needs to be after checking the variable, or else it will always be true obviously.

Hope that helps!
B
28
S
8
G
5
Posts: 429
Reputation: 6,997

Post » Sun Jul 28, 2013 10:16 pm

1.-use a text instance variable in your items, like: "howManyTimesHaveThisBeenHit".
2.- on first hit, set it to "first",
3.- on second hit, set it to "second"
California2013-07-28 22:16:57
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Sun Aug 04, 2013 4:38 am

Thanks guys! Appreciate your input. I haven't been able to make either idea work yet but I'm still working on it. I think I'm getting close though.
B
19
S
8
G
3
Posts: 73
Reputation: 4,145


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest