Search code examples
objective-cinheritancecocos2d-iphonetouchesbegansubclass

in cocos2d can ccTouchesBegan be in a class not subclassed from ccLayer?


Hello I am making a side scrolling cocos2d game. I have one class subclassed from CCLayer and other classes subclassed from CCSprite and CCNode. Can I use the ccTouch methods in the classes subclassed from CCSprite and CCNode, or can they only be in the class subclassed from CCLayer?


Solution

  • Try this

    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
    

    and call

    - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
        return YES;
    }