Checking if a button is down

Discussion in 'Public Game Developers Forum' started by kohjingyu, Jun 3, 2009.

  1. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    Hey Guys,
    I wanted to know how do you check if you are pressing a button? I wanted to set off an action as long as the button is down, but now I can only set it off it I press it! If I press it once, the action is only done once. I want to do it as long as I am pressing the button.
     
  2. rdklein

    rdklein Well-Known Member

    Apr 3, 2009
    384
    0
    0
    sw developer, tv producer, hw developer (microcodi
    Munich
    best is to use the touchbegin, touchend and set flags when the messages arriv in the veiw, probably you have to check with pointinrect if you hit the real button at that time.
     
  3. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    I want to move an image to the right if I press it. The problem now is that it only moves when I press it. I don't really understand what you are talking about, but thanks. It's not a message, I want to move an image.
     
  4. PixelthisMike

    PixelthisMike Well-Known Member

    I have a feeling one of the example apps provided by Apple might implement this functionality... anyone recall? It's been a while since I looked at the Apple example apps.

    rdklein is referring to the touchesBegan:withEvent: and touchesEnded:withEvent: messages which are inherited by UIButton objects from the UIResponder class. Check the documentation for the UIResponder class.

    Ah just found the Apple example app, it's called MoveMe so hunt out the source for that and that should help you along the way.
     
  5. WellSpentYouth

    WellSpentYouth Well-Known Member

    Jan 11, 2009
    1,363
    6
    0
    iPhone programmer
    App Tech Studios, USA
    If you want to do something when you press the button and something else when you unpress, just make 2 IBActions, go into IB, select your button, right click, scroll down on that black/grey pop-up thing to Touch Down and drag it to the press down method and do the same thing only find Touch Up Inside and drag it to the touch up method.


    I hope this is helpful!
     
  6. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    #6 kohjingyu, Jun 3, 2009
    Last edited: Jun 4, 2009
    Okay, so when I touch down on the button, I start an NSTimer which sets off an action to move the ball right. Now, when I touch up inside, I want to stop that timer. Any way to do this?
     

Share This Page