如何在Sprite Kit - Swift中通过一系列CGPoints进行动画处理

时间:2017-05-08 10:14:06

标签: ios swift3 sprite-kit

如何在swift的SKSpriteNode数组中为CGPoints设置动画?我还希望SKSpriteNode向下一个位置旋转。任何帮助将不胜感激。

1 个答案:

答案 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")

    } 
}
相关问题