How do I pick an object if it's withing a specified position

Get help using Construct 2

Post » Sat May 31, 2014 3:12 pm

Say there 100 copies of an apple and 1 orange on screen and the apples and the orange are continuously moving in random directions. Say i only want to pick the apple that is 5 pixels to the right of the orange at any given instant. How do i go about doing this?.

And also i want to set a global variable to 1 whenever an apple is 5 pixels to the right of orange and then back to zero when no apple is 5 pixels to the right of orange.

I seem to either not be able to pick an apple or when i do pick an apple and set variable to 1,i'm unable to reset the variable back to zero.
B
16
S
4
Posts: 140
Reputation: 1,458

Post » Fri Jun 06, 2014 6:12 am

Just make another sprite 5 pixels bigger than the orange and pin it to the orange position. Then just check if an apple is overlapping this new sprite and set the variable to 1 if it is overlapping and 0 if it is not.
B
10
S
4
Posts: 133
Reputation: 1,543

Post » Fri Jun 06, 2014 7:14 am

Alternatively pick an instance by evaluating if the apple's X position is 5 greater than the orange.

Code: Select all
System|Pick Apple by evaluating (Apple.X - Orange.X) = 5


If you just want distance (to left or right) then use

Code: Select all
System|Pick Apple by evaluating abs(Apple.X - Orange.X) <= 5


And set your variable based on that.

Then you could check
Code: Select all
Apple.PickedCount
and reset it if this = 0.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jun 06, 2014 9:49 am

hi,
use the "CompareX" to detect your eneymies and pick them
i have a little tutorial here : https://www.scirra.com/tutorials/1022/c ... form-games
after destoying, edit your variables with "Set Value".
2D Game GUI Designer
B
12
S
4
G
3
Posts: 130
Reputation: 3,778


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 45 guests