cocos2d通过触摸无间隙地拖动精灵

时间:2013-03-24 17:00:54

标签: cocos2d-iphone

我试图通过触摸来拖动精灵。如果触摸在精灵之外,则不应移动。

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

我正在使用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)];
    }
}

有任何建议如何实现吗?

0 个答案:

没有答案