Thursday 21 July 2011

Getting touch recognition anywhere on the screen with cocos2d

Had to google around for this, cocos2d doesn't let the user have touch recognition off the bat, you have to have
"self.isTouchEnabled = YES;
in the init function of the layer you want touch recognition. Then outside of the init function you have to write:
-(void) registerWithTouchDispatcher {
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];

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

//this function is optional
-(void) ccTouchEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//your code here   

Seems a bit unnecessary :/

No comments:

Post a Comment