我在移动通过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轴上移动它。我很困惑,它可能有很多东西,但我在想也许我只需要设置速度或其他什么,但如果是这样,什么是合适的设置?
发布于 2013-10-31 06:31:29
这应该可以解决问题,我还建议你在抓取精灵时关闭物理,在释放时再次打开图灵。
- (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;
}https://stackoverflow.com/questions/19693507
复制相似问题