如何讓精靈坐在移動的精靈上並隨其移動。我讓紅色盒子衝動地跳起來,當紅色盒子落在正在移動的黑色塊子上時,紅色盒子停留在它掉落的地方,滑動移動的物體,就像沒有摩擦。條件引力,摩擦1.0甚至試圖增加質量,但沒有奏效。請給我任何細節如何使它工作? 感謝 覆蓋FUNC didMoveToView(查看:SKView){ /*設置你這裏的場景*/如何讓精靈坐在移動的精靈上
self.physicsWorld.gravity = CGVectorMake(0.0, -9.8)
SquareOne.fillColor = UIColor.orangeColor()
SquareOne.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
SquareOne.physicsBody = SKPhysicsBody(rectangleOfSize: SquareOne.frame.size)
SquareOne.physicsBody?.friction = 1.0
SquareOne.physicsBody?.restitution = 0.0
addChild(SquareOne)
SquareTwo.fillColor = UIColor.greenColor()
SquareTwo.position = CGPoint(x: self.frame.midX, y: self.frame.midY - 100)
SquareTwo.physicsBody = SKPhysicsBody(rectangleOfSize: SquareTwo.frame.size)
SquareTwo.physicsBody?.dynamic = false
SquareTwo.physicsBody?.affectedByGravity = false
SquareTwo.physicsBody?.friction = 1.0
SquareTwo.physicsBody?.restitution = 0.0
addChild(SquareTwo)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
SquareTwo.runAction(SKAction.moveByX(-100, y: 0.0, duration: 3.0))
}
}
爲了使這一更加簡單,如果有兩個街區紅色和黑色。紅色受重力影響,黑色不會影響我的重力。觸摸開始功能一旦我觸摸黑色開始在x方向移動。當它移動紅色塊滑倒。如何使它附着在黑塊上。 –
你有正確的想法。你只需要使用物理學來移動黑塊。這是如何http://stackoverflow.com/questions/31590885/how-to-move-platform-with-velocity – 0x141E