2013-10-30 13 views
0

我無法移動通過SKPhysicsJoint附加的精靈。我有一個touchesMoved方法,看起來像這樣:拖動通過SKPhysicsJoints附加的Sprites的最佳方式?

- (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軸上移動它。我很困惑,可能有很多事情,但我想也許我只需要設置速度或其他東西,但如果是這樣,那麼什麼是合適的設置?

回答

1

這應該解決問題,我也建議關閉物理,當你抓住精靈,並釋放時再次turing。

- (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; 
} 
+0

對不起,我剛纔還看見這樣的回答:|問題是,通過關閉物理,關節斷裂,並且只能拖動一個物體。 – Cocorico

+0

如果你離開物理,我想你會得到那個波濤洶涌的動作? – DogCoffee

+0

如果我離開了物理,但是將兩個精靈的受影響的集合度設爲= NO,我避免了我認爲你的意思是波濤洶涌的運動。 – Cocorico