iOS开发中使用cocos2d添加触摸事件的方法

2020-01-14 16:58:26王冬梅

    CGPoint location = [touch locationInView: [touch view]];

    location = [[CCDirector sharedDirector] convertToGL: location];

    //self.position = location;

     NSLog(@"point==%@",NSStringFromCGPoint(location));

}

 

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {

    self.isMoving = FALSE;

}

 

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

   

    // you can set up a check here if you're not interested in handling every touch.

    // For example if your player is already moving, return no...

   

    BOOL handleTouch = FALSE;

    if (!self.isMoving) {

        handleTouch = TRUE;

        self.isMoving = TRUE;

    }

    return handleTouch;

   

}



注:相关教程知识阅读请移步到IOS开发频道。