Author Topic: new press event on state change...  (Read 3513 times)

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
new press event on state change...
« on: November 20, 2012, 03:46:48 PM »
hey guys,

i have an eventListenPressed on a sprite. let's say i have two game states, one in which presses are allowed (STATE_CAN_PRESS) and one in which presses are not allowed (STATE_CAN_NOT_PRESS). i'd like the user to be able to press the sprite during STATE_CAN_NOT_PRESS and as soon as the state changes to STATE_CAN_PRESS the press event will register.

anyone know a good way to achieve this? perhaps a way to make currentTouch into a new touch when the state changes...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: new press event on state change...
« Reply #1 on: November 20, 2012, 03:51:11 PM »
Eh? You are the one that will write this script, so you can keep it simple:

  1. void OnPress (bool isPressed)
  2. {
  3.     if (canPress && isPressed) <do stuff>;
  4. }

Setting the sprite is equally trivial: sprite.spriteName = "Sprite Name";

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
Re: new press event on state change...
« Reply #2 on: November 20, 2012, 05:29:36 PM »
in your example, OnPress only fires once when the user first presses. if the user is holding their finger down on the sprite when canPress becomes true, <do stuff> will not occur. the user will have to lift their finger and press again.

i guess what i'm looking for is more of an update function that runs while a sprite is pressed. like WhilePressing() rather than OnPress().

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: new press event on state change...
« Reply #3 on: November 20, 2012, 05:57:06 PM »
Then you need to add an Update() function that will check for that logic. :P