0

我正在尝试通过触摸来拖动精灵。如果触摸在精灵之外,它不应该移动。

当用户触摸精灵并拖动它时,会在后面绘制一条路径。这条路径不应被破坏(如路径之间的间隙)。任何时候都应该有一条一致的路径。

我正在使用 mysprite.position 将精灵的新位置设置为与当前触摸位置相同。但是,如果用户触摸稍微偏离路径的点,则会出现间隙。我也尝试使用 CCMoveTo 动作,但这会延迟路径绘制,如果用户绘制速度非常快,那么精灵跟在后面看起来很糟糕。

-(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)];
    }
}

任何建议如何实现它?

4

0 回答 0