0

I add a button as spriteNode to a scene, and i want to run an action when the touch cancelled.

I add a "touches-cancelled" method and write an "NSLog" to test if this method is called. After I run my project, there is no output showing this method is called.

how can i run the "touches cancelled" method to my button?

twernt
  • 20,271
  • 5
  • 32
  • 41
Tongyue
  • 23
  • 5
  • 3
    Touch cancelled is only called when something unexpected happened (like a phone call). Try to overwrite `touchesEnded:` – dasdom Mar 27 '14 at 07:21
  • Do you want to call a method when the button is touched? OR when the button press is cancelled OR when overall touches are cancelled? – Woodstock Mar 27 '14 at 09:10
  • I call a method which changes the image of the button when user clicks the button. I want another method to change the image back to the previous one when the user moves finger out of the button. – Tongyue Mar 27 '14 at 09:24

1 Answers1

0

To be able to effectively implement something like touchesCancelled on a button node based on the touchPosition, you will need to subclass SKSpriteNode to act as a button. It will have to implement the touch delegates on it's own.

A sample of how to do this can be found in this answer:

https://stackoverflow.com/a/19199748/2043580

It includes code which sets the texture back to the unselected state when the touchPoint goes out of the node's bounds in the -touchesMoved method.

Community
  • 1
  • 1
ZeMoon
  • 20,054
  • 5
  • 57
  • 98