0

我无法移动通过 SKPhysicsJoint 附加的精灵。我有一个如下所示的 touchesMoved 方法:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    CGPoint previousPosition = [touch previousLocationInNode:self];
    CGPoint translation = CGPointMake(positionInScene.x - previousPosition.x, positionInScene.y - previousPosition.y);
    CGPoint newPosition = CGPointMake(_selectedNode.position.x + translation.x, _selectedNode.position.y + translation.y);
    [_selectedNode runAction:[SKAction moveTo:newPosition duration:0]];
}

它有点工作,但如果我将重力设置得非常低,它似乎只能将精灵移动 25%,如果我将重力设置为默认值,它几乎不会在 y 轴上移动。我很困惑,可能有很多东西,但我想也许我只需要设置速度或其他东西,但如果是这样,什么是合适的设置?

4

1 回答 1

1

这应该可以解决问题,我还建议在您抓住精灵时关闭物理,并在您释放时再次打开。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    CGPoint previousPosition = [touch previousLocationInNode:self];
    CGPoint translation = CGPointMake(positionInScene.x - previousPosition.x, positionInScene.y - previousPosition.y);
    //_selectedNode.physicsBody.dynamic = NO;
    [_selectedNode setPosition:CGPointMake(_selectedNode.position.x + translation.x, _selectedNode.position.y + translation.y)];
}

如果你想再次打开物理

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    _selectedNode.physicsBody.dynamic = YES;
}
于 2013-10-30T22:31:28.713 回答