我使用Cocos2D和Kobold2D制作游戏。在我的游戏,我有我想要移动到播放器水龙头,使用此代码的船舶:CCMoveTo引起跳跃
KKInput * input = [KKInput sharedInput];
CGPoint tap = [input locationOfAnyTouchInPhase:KKTouchPhaseBegan];
if (tap.x != 0 && tap.y != 0)
{
[ship stopAllActions]; // Nullifies previous actions
int addedx = tap.x - ship.position.x;
int addedy = tap.y - ship.position.y;
int squaredx = pow(addedx, 2);
int squaredy = pow(addedy, 2);
int addedSquares = squaredx + squaredy;
int distance = pow(addedSquares, 0.5);
[ship runAction: [CCMoveTo actionWithDuration:distance/100 position:tap]];//makes ship move at a constant speed
}
船一般移动,因为我希望它。但是,如果我在船的附近轻敲,而不是顺利地移动到水龙头位置,则会跳到该位置。我该如何解决?
这是因为actionWithDuration的,您所提供的,在CCMoveTo行动。 – Renaissance