【问题标题】:How can I use GameplayKit State Machine for sprite animation?如何使用 GameplayKit 状态机进行精灵动画?
【发布时间】:2020-04-18 16:36:40
【问题描述】:

我有两个动画让我的玩家奔跑和跳跃。我可以使用 GameplayKit 的状态机来控制这些动画吗?如果是这样,怎么做?在这个项目中,我将 SpriteKit 和 GameplayKit 用于实体组件架构和状态机。

【问题讨论】:

    标签: sprite-kit gameplay-kit


    【解决方案1】:

    您需要先设置 StateMachine 并填写您的自定义类

    self.playerStateMachine = GKStateMachine(states: [
        PlayerRunning(player),
        PlayerJumping(player)
    ])
    

    然后当你需要进入状态时,可以用:

    self.playerStateMachine?.enter(PlayerRunning.self)
    

    在状态上,您可以执行如下更改:

    override func didEnter(from previousState: GKState?) {
        self.player?.run(runAnimation)
    }
    

    例子:

    请在此处查看完整示例:https://github.com/Maetschl/SpriteKitExamples/blob/master/StateMachineAnimation/StateMachineAnimation/GameScene.swift

    【讨论】:

    • 谢谢你,Maetschl。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2011-12-01
    • 2013-10-08
    相关资源
    最近更新 更多