1
我現在擁有:節點當前只在x軸上以直線行進。如何使SKSpriteNode落在下降曲線
let actionBomb = SKAction.repeatForever(SKAction.moveTo(x: 495, duration: 3.0))
我正在尋找實現:我們的目標是要擁有一個向下的曲線節點行程,直到擊中地面。我不知道如何去實現這一點。
這裏是我當前的代碼:
func bombAction(){
if(self.action(forKey: "spawnBomb") != nil){return}
let bombTimer = SKAction.wait(forDuration: 5, withRange: 8)
let spawnbombA = SKAction.run {
self.bomb = SKSpriteNode(imageNamed: "bomb1")
self.bomb.zPosition = 1
self.bomb.physicsBody = SKPhysicsBody(circleOfRadius: self.bomb.size.height/10.0)
self.bomb.physicsBody?.isDynamic = true
self.bomb.physicsBody?.allowsRotation = false
self.bomb.physicsBody?.affectedByGravity = true
var bombPosition = Array<CGPoint>()
bombPosition.append((CGPoint(x:400, y:475)))
bombPosition.append((CGPoint(x:500, y:475)))
bombPosition.append((CGPoint(x:750, y:475)))
let shuffledLocations = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: bombPosition) as! [CGPoint]
self.bomb.position = shuffledLocations[0]
let spawnLocationBomb = bombPosition[Int(arc4random_uniform(UInt32(bombPosition.count)))]
let actionBomb = SKAction.repeatForever(SKAction.moveTo(x: 495, duration: 3.0))
self.bomb.run(actionBomb)
self.bomb.position = spawnLocationBomb
self.addChild(self.bomb)
print(spawnLocationBomb)
}
let sequenceBomb = SKAction.sequence([bombTimer, spawnbombA])
self.run(SKAction.repeatForever(sequenceBomb), withKey: "spawnBomb")
}
動作:SKAction.moveTo不受重力影響,移動炸彈,你應該使用衝動力來代替。檢查[this](https://developer.apple.com/reference/spritekit/skphysicsbody/1519900-applyimpulse) –