您的位置:首页 > 移动开发 > Cocos引擎

cocos2d 触摸事件

2011-01-19 23:34 267 查看
首先添加事件接收者:

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:NO];

//self为接收者, 优先级参数从0开始 数字越小优先级越高,就会越先接收到事件, 最后一个参数表示是否阻止此次事件冒泡

然后实现3个方法:

#pragma mark TouchDispatcherDelegate

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

//你的代码

return YES; //这儿如果返回NO 此次触摸将被忽略

}

- (void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event

{

//你的代码

}

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

//你的代码

}

[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: