0

I am trying to do something fairly simple in Cocos2d 3.1. I am receiving touch events on a CCSprite subclass and I am trying to stop receiving touch events when the touch is slid off of the sprite using a simple containsTouchLocation helper method.

What is not working however is if I do self.userInteractionEnabled = NO; in the touchMoved: method, it still calls touchMoved!

This is my full touchMoved: method:

- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
    self.userInteractionEnabled = NO;
    int color = ([self containsTouchLocation:touch] ? 128 : 255);
    self.color = [CCColor colorWithCcColor3b:ccc3(color, color, color)];
} 

Why is it that even though I am clearly trying to turn off touch events in the touchMoved method, it is still calling it?

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
  • does it maybe only affect the current touch, ie interaction disabled only takes effect for future touches while the current touch is allowed to receive moved and ended events? – CodeSmile Jul 20 '14 at 21:30
  • @LearnCocos2D Yes it appears it stops all future touches. How would I stop the current touch? – SimplyKiwi Jul 20 '14 at 22:13
  • From what I researched, there isn't a way to do this. So for the meantime I just used a BOOL and won't call the code when need be. Do you know if there is a way to stop touch events for a touch that is still in action? – SimplyKiwi Jul 20 '14 at 22:25

1 Answers1

0

Deactivating userInteractionEnabled on an active touch does not cancel a touch in the current version of Cocos2D. I have created a pull request to change that, because in my opinion nodes should only receive touch events while userInteractionEnabled is set to YES(https://github.com/cocos2d/cocos2d-iphone/pull/882)

For now you will have to handle that with some sort of state variable in your node that receives touches.

Ben-G
  • 4,996
  • 27
  • 33