iOS Dev (70) 让 CCLayer 接受触摸或加速计事件
- 博客:http://blog.csdn.net/prevention
- 作者:大锐哥
- 摘自:
Learn iPhone and iPad cocos2d Game Development
-
触摸事件
首先要开启接受 touch events 的开关:
self.isTouchEnabled = YES;
然后是处理函数:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event {}
ccTouchBegan返回的是一个布尔值(BOOL)。如果你返 回了YES,那就意味着你不想让当前的触摸事件传导到其它触摸事件处理器。你 实际上是“吞下了”这个触摸事件。
加速计事件
开启开关:
self.isAccelerometerEnabled = YES;
处理函数:
-(void) accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
CCLOG(@"acceleration: x:%f / y:%f / z:%f",
acceleration.x, acceleration.y, acceleration.z);
}
-
转载请注明来自:http://blog.csdn.net/prevention