I got a question about two spawn actors with overlapping
fongor
Member, PRO Posts: 18
Actor A n B is two actors which I spawn ,I set a rule:when i touch it,it will destroy,I want to touch A ,so I randomly touch A position,but when I touch on the common part C, A n B will destroy at the same time.How can I solve this problem?Thanks a lot!,
Comments
How to select overlapping actors in Gamesalad tutorial PART 1
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks for your help!But it seems doesn't work on spawn actor
I assume you can also destroy B, if you wanted to destroy B how would you do it ?
When you touch the common area C, which actor do you want destroyed ?
if A is above of B, destroy A
if B is above of A, destroy B
How are you detecting which actor is 'above' ?
The actor is a image,it can differentiated by us
1) Give each spawned actor a unique ID number.
2) Spawn your actors make so that they spawn to 'front of layer'.
3) Now when you click on an actor, have it copy its ID to a game attribute (let's call it 'X').
The fact that GameSalad scans actors from the bottom to the top (with regard to layers) means if you were to click on, for example, 3 actors stacked on top of each other they will all copy their ID to X, but this will happen one at a time, in order from bottom to top, with the final actor (the highest in the layers) being the last to copy its ID to X (writing over the previous values).
4) Now have a rule in the actor that says when self.ID = X, then destroy.
The result is that only the top actor, in a stack of actors, will be destroyed.
Here's a quick example, click on actors to destroy.
(GameSalad file attached below)
//
Here's a somewhat simpler way, just click on an actor to drag, only the topmost actor will be dragged, even when it's on top of a stack of other actors. (file attached)
This method exploits the fact that actors are scanned from the bottom to the top in the layer order.
tl;dr
. . . there's a simple way to determine layer order, have the actors change a global attribute in some way, the highest actor will be the last to change this attribute as GS scans layers bottom to top.