Ios 如何在Cocos2D V3上检测CCS场景中的触摸?
我知道你过去可以通过以下方式做到这一点:Ios 如何在Cocos2D V3上检测CCS场景中的触摸?,ios,objective-c,cocos2d-iphone,touch,Ios,Objective C,Cocos2d Iphone,Touch,我知道你过去可以通过以下方式做到这一点: <CCLayerObject>.isTouchEnabled = YES; …然后就可以得到回拨: -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint point = [self convertTouchToNodeSpace:touch]; NSLog(@"X:%ftY:%f", point.x, point.y); } 但是
<CCLayerObject>.isTouchEnabled = YES;
…然后就可以得到回拨:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint point = [self convertTouchToNodeSpace:touch];
NSLog(@"X:%ftY:%f", point.x, point.y);
}
但是在V3中您需要做什么呢?看起来我所要做的就是: 在CCScene构造函数中,启用触摸:
[self setUserInteractionEnabled:YES];
self.userInteractionEnabled = YES;
将TouchStart方法添加到:
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
NSLog(@"touchBegan");
}
塔达!V3比V2容易得多
还可以选择:
[self setMultipleTouchEnabled:YES];
在COCOS2D3.0中,任何CCNode都可以接收触摸。您只需启用触摸功能:
[self setUserInteractionEnabled:YES];
self.userInteractionEnabled = YES;
然后有四种不同的方法来处理触摸:
[self setUserInteractionEnabled:YES];
self.userInteractionEnabled = YES;
- 触摸开始:当用户触摸屏幕时调用
- 触摸移动:: 当用户在屏幕上移动手指时调用
- touchEnded:当用户停止触摸屏幕时调用
- touchCancelled:当用户仍在触摸屏幕时调用
但其他一些问题会阻止您的节点处理触摸(例如
触摸移动到节点边界之外)
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInNode:self];
currentHero.position = touchLocation;
}
您可以在本touch教程中阅读更多内容:可能重复@iPhoneProcessor LOL。这个问题是针对Cocos2D 2.0的……您忘记阅读标题了吗?我在中已经找到了有关Touchs问题的答案v3@iPhoneProcessor抱歉,但这不算是“重复问题”LOL