Cling to actor and destroy when touched: Suggestions needed!

iPhoneDevForMeiPhoneDevForMe Member Posts: 362
edited November -1 in Working with GS (Mac)
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

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    might just need in the touch pressed a rule that √s game.Attached state and then Destroy

    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
  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    Looks like a good solution, the nesting is where I had some hiccups! I'll have to try it tonight when I get home and I'll let you know how it works! Thanks a lot!
  • ORBZORBZ Member Posts: 1,304
    Just a hunch,
    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.
  • MotherHooseMotherHoose Member Posts: 2,456
    Great tip ORBZ ...as always!

    MH
Sign In or Register to comment.