I can't understand why if I subclass a SKSpriteNode, that implements the UIResponder protocol, the methods related with touches are never been called.
For example, this is a really simple class that I'm using as test:
//INTERFACE ----------------
#import <SpriteKit/SpriteKit.h>
@interface TestClass : SKSpriteNode
@end
//IMPLEMENTATION -----------
#import "TestClass.h"
@implementation TestClass
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"oook");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{}
@end
If I attach an instance of this class to the scene, touching the object... nothing happens.
Am I forgetting something?
I've just seen that SKNode has the parameter userInteractionEnabled by default equal to NO. Just set it to YES to make the code works properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With