Cocos2d iphone cocos2d无间隙触摸拖动精灵
我正试图通过触摸来拖动一个精灵。如果触摸在精灵外部,则不应移动 当用户触摸并拖动精灵时,会在其后面绘制一条路径。此路径不应断开(如路径之间的间隙)。应该始终有一条一致的路径 我正在使用mysprite.position将精灵的新位置设置为与当前触摸位置相同。 但是,如果用户接触的点稍微偏离路径,则会有间隙。 我还尝试使用CCMoveTo操作,但这会延迟路径绘制,如果用户绘制速度非常快,那么sprite跟在后面看起来很糟糕Cocos2d iphone cocos2d无间隙触摸拖动精灵,cocos2d-iphone,Cocos2d Iphone,我正试图通过触摸来拖动一个精灵。如果触摸在精灵外部,则不应移动 当用户触摸并拖动精灵时,会在其后面绘制一条路径。此路径不应断开(如路径之间的间隙)。应该始终有一条一致的路径 我正在使用mysprite.position将精灵的新位置设置为与当前触摸位置相同。 但是,如果用户接触的点稍微偏离路径,则会有间隙。 我还尝试使用CCMoveTo操作,但这会延迟路径绘制,如果用户绘制速度非常快,那么sprite跟在后面看起来很糟糕 -(void)ccTouchesBegan:(NSSet *)touche
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[mySprite runAction:[CCMoveTo actionWithDuration:0.0f position:touchLocation]];
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if(CGRectContainsPoint([mySprite boundingBox], currentTouchPoint)){
CGPoint translation = ccpSub(currentTouchPoint, lastTouchPoint);
CGPoint newPos = ccpAdd(mySprite.position, translation);
mySprite.position = newPos;
[touchPoints addObject:NSStringFromCGPoint(currentTouchPoint)];
[touchPoints addObject:NSStringFromCGPoint(lastTouchPoint)];
}
}
有什么建议吗?在触摸位置之间插入,因为如果用户快速移动手指,两个触摸事件的位置可能相距很远。您能建议如何实现吗?有人有一些好主意来实现吗?请分享。