cocos2d点滴-添加触摸事件
来源:互联网 发布:php防cc攻击代码怎么用 编辑:程序博客网 时间:2024/06/01 07:48
在自己的layer里面,添加
[self setIsTouchEnabled:YES];
以下方法是cocos2d类库的方法:
-(void) setIsTouchEnabled:(BOOL)enabled
{
if( isTouchEnabled_ != enabled ) {
isTouchEnabled_ = enabled;
if( isRunning_ ) {
if( enabled )
[self registerWithTouchDispatcher];
else {
CCDirector *director = [CCDirector sharedDirector];
[[director touchDispatcher] removeDelegate:self];
}
}
}
}
//这句是关键
-(void) registerWithTouchDispatcher
{
CCDirector *director = [CCDirector sharedDirector];
[[director touchDispatcher] addStandardDelegate:self priority:0];
}
接下来就实现方法:
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// for( UITouch *touch in touches ) {
// CGPoint location = [touch locationInView: [touch view]];
//
// location = [[CCDirector sharedDirector] convertToGL: location];
// CGPoint touchPos = location;
//
// NSLog(@"point==%@",NSStringFromCGPoint(touchPos));
// }
UITouch* touch = [touches anyObject];
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;
}
- cocos2d点滴-添加触摸事件
- cocos2d-x基础学习--添加触摸事件
- 在cocos2d上添加UIView,触摸事件往下传递
- cocos2d-x添加触摸层阻止后端事件
- cocos2d-html5学习之三-为sprite添加触摸事件
- cocos2d-html5学习之三-为sprite添加触摸事件
- cocos2d 触摸事件
- cocos2d 触摸事件跟踪
- cocos2d - 触摸事件
- cocos2d接收触摸事件
- cocos2d-lua 触摸事件
- Cocos2d-JS 触摸事件
- COCOS2d中添加UIButton不响应触摸事件---iOS开发之最灵异事件之2
- [js点滴]触摸事件与手势事件
- android添加触摸事件
- [js点滴]JavaScript之触摸事件07
- cocos2d开发之触摸事件
- cocos2d 触摸事件的传递
- 多线程编程最新资料大全
- 报错: Undefined symbols for architecture i386 error
- OpenGL程序二:实现纹理映射到3D立方体上
- 黑盒测试方法
- java-15位身份证号升级到18位
- cocos2d点滴-添加触摸事件
- mmap gcc 静态库 动态库
- ibatis中输入/输出各种类型的参数分析及#与$区别
- java-压缩目录生成ZIP包
- 在 SVG 中添加交互性
- 将字符串或表达式直接转为C#可执行代码的办法
- XML基础学习
- 使用curl发起https请求
- LXC学习