Cling to actor and destroy when touched: Suggestions needed!
iPhoneDevForMe
Member Posts: 362
So I have an actor that moves by tilting the iPhone. I have an enemy who flies across the screen randomly. When it collides with my moving actor, it clings to it and you have to tap the enemy to destroy it. I'm having a big issue with this. Half the time I tap the enemy, it destroys right away, the other half, I have to tap it again and again, sometimes for 5 sec repeatedly before it finally destroys itself. Here are my rules:
When actor collides with ship and attribute game.Attached is false
---Change attribute self.cling to true
---Change attribute game.Attached to true
When self.cling is true
---constrain attribute self.position x,y to ship x,y
When attribute self.cling is true and actor receives touch pressed
---Change attribute game.Attached to false
---Destroy actor
Any one have an idea on a better more stable method? I've spent quite some time arranging the rule sets and playing with variables and it just does not work correctly.
Thanks a lot!
-Kyle
When actor collides with ship and attribute game.Attached is false
---Change attribute self.cling to true
---Change attribute game.Attached to true
When self.cling is true
---constrain attribute self.position x,y to ship x,y
When attribute self.cling is true and actor receives touch pressed
---Change attribute game.Attached to false
---Destroy actor
Any one have an idea on a better more stable method? I've spent quite some time arranging the rule sets and playing with variables and it just does not work correctly.
Thanks a lot!
-Kyle
Comments
sorta:
[Rule]
--actor collides with ship
--game.Attached = false
----
. change attribute self.cling to true
. change attribute game.Attached to true
. [Rule]
. --self.cling = true
. --game.Attached is true
. ----
. [Rule]
. --actor receives touch pressed
. ----
. change attribute game.Attached to false
. [Rule]
. game.Attached = false
. -----
. Destroy actor
nest the rules...so if you call for an attribute change you immediately access that attribute's state and then initiate action.
well you could copy/paste that pseudo code in a Note in your GS project and try to make some sense of it with the behaviors.
also like touch inside rather than touch pressed for these things...
MH
Pressed and released events can get stuck on the stack. To avoid the create a Boolean "pressed" that is set to true in the pressed event and false in the released event.
Then test the state of the Boolean to execute your game logic.
MH