如何在swift的SKSpriteNode
数组中为CGPoints
设置动画?我还希望SKSpriteNode
向下一个位置旋转。任何帮助将不胜感激。
答案 0 :(得分:1)
你可以这样做:
import SpriteKit
class GameScene: SKScene,SKSceneDelegate {
override func didMove(to view: SKView) {
//1. create points
let points = [CGPoint(x:120,y:20),CGPoint(x:220,y:20),CGPoint(x:40,y:320)]
var actions = [SKAction]()
//2. Create actions
for point in points {
actions.append(SKAction.move(to: point, duration: 1))
}
let sprite = SKSpriteNode(color: .white, size: CGSize(width: 100, height: 100))
addChild(sprite)
//3. Create the action sequence from previously created actions
let sequence = SKAction.sequence(actions)
//4. Run the sequence (use the key to stop this sequence)
sprite.run(sequence, withKey:"aKey")
}
}