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.
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.
Develop games in your browser. Powerful, performant & highly capable.
Alternatively pick an instance by evaluating if the apple's X position is 5 greater than the orange.
System|Pick Apple by evaluating (Apple.X - Orange.X) = 5[/code:36sk8ks0]
If you just want distance (to left or right) then use
[code:36sk8ks0]System|Pick Apple by evaluating abs(Apple.X - Orange.X) <= 5[/code:36sk8ks0]
And set your variable based on that.
Then you could check [code:36sk8ks0]Apple.PickedCount[/code:36sk8ks0] and reset it if this = 0.
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".