我正在尝试使用cocos2d开发游戏。我现在卡住了。我不知道如何检测双击事件,就像在Windows中双击一样。我尝试使用
NSArray * allTouches = [touches allObjects];
int count = [allTouches count];
ccTouchesEnded
中的
但是,当双重触摸同时发生时,这似乎有效。我想要在Windows中的样子。
有人能给我一些想法吗? 提前谢谢。
答案 0 :(得分:3)
如果您使用targetedTouchDelegate,则可以执行以下操作:
- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
if(touch.tapCount==1) MPLOG(@"ONE TAP");
if(touch.tapCount==2) MPLOG(@"TWO TAPS");
return;
}
当双击发生时,您将获得两次触摸,即当双击时,这将记录“ONE TAP”和“TWO TAPS”。由你决定你的状态并做你的事情。
答案 1 :(得分:2)
你在谈论多点触控2指点击或双击如mac和windows?
如果是双击,就像在Mac和Windows中一样,那么这里就是解决方案。
你可以用两种方式做到这一点。
使用UITapGestureRecognizer(设置为检测双击)由LearnCocos2D在此question中建议。
使用时差来手动双击跟踪。
//在界面文件中删除此内容
NSTimeInterval mLastTapTime;
在实施文件中:
-(id)init
{
if(self = [super init])
{
mLastTapTime = [NSDate timeIntervalSinceReferenceDate];
}
return self;
}
//触摸式方法
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval diff = currentTime - mLastTapTime;
if(diff < 0.5 ) //0.5 or less
{
//double tap
}
mLastTapTime = [NSDate timeIntervalSinceReferenceDate];