Cocos2d iphone 与CCTouches的问题已开始
上面的代码有什么问题?pre和curr变量gve输出相同?当触摸开始时,显然没有以前的触摸,因为触摸刚刚开始。所以之前的位置和位置都是相同的Cocos2d iphone 与CCTouches的问题已开始,cocos2d-iphone,Cocos2d Iphone,上面的代码有什么问题?pre和curr变量gve输出相同?当触摸开始时,显然没有以前的触摸,因为触摸刚刚开始。所以之前的位置和位置都是相同的 如果您在ccTouchesMoved中运行此代码,它将按预期工作。您只需在ccTouchesEnded方法中打印当前位置即可。这将给你两点之间的区别 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]
如果您在ccTouchesMoved中运行此代码,它将按预期工作。您只需在ccTouchesEnded方法中打印当前位置即可。这将给你两点之间的区别
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point1 = [touch previousLocationInView:[touch view]];
CGPoint point2 = [touch locationInView:[touch view]];
point1 = [[CCDirector sharedDirector]convertToGL:point1];
point2 = [[CCDirector sharedDirector]convertToGL:point2];
pre = point1;
curr = point2;
CCLOG(@"the pre location is %@",NSStringFromCGPoint(pre));
CCLOG(@"the curr location is %@",NSStringFromCGPoint(curr));
}
因此,您只需在CCTouchesBegind方法中获取
previousLoaction
。我的应用程序有以下要求:我在一个点上选择一个精灵,然后我想移动到下一个接触点
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event