【问题标题】:Link SKNode to GKAgent2D?将 SKNode 链接到 GKAgent2D?
【发布时间】:2016-03-02 02:46:51
【问题描述】:

我是 GameplayKit 的新手,因为大多数人都知道它的使用寿命,并且一直在尝试弄清楚以下内容..

我有一个SKNode *enemy,它已经从SpriteKit 完成了从动作到风格、习惯等的大量工作和定制。我的问题是这样的:

  • 如何将我的敌人节点“链接”到GKAgent2D,以便它控制该节点的移动?

我知道您必须创建一个GKComponent 并使用可能具有特定纹理选择的 Sprite 节点来表示此组件。但我想知道是否有办法使用GameplayKit 在现有节点上提供的内置“控制移动”方法。如果答案是“否”,请直接说出来并解释为什么?我很感激任何帮助。谢谢!

【问题讨论】:

    标签: ios sprite-kit sknode gameplay-kit


    【解决方案1】:

    你的敌人是 GKEntity 吗?如果不是,我相信您不能向其中添加 GKComponent。

    如果你的敌人是 GKEntity,那么你只需添加一个 GKComponent 作为代理。否则你将不得不改变你的敌人类以使其成为 GKEntity。

    Apple 在 DemoBots 中的做法是创建一个类

    class AgentComponent: GKAgent2D { }
    

    (GKagent 是 GKComponent 的子类,所以就像添加一个组件)

    比在他们需要代理的实体中他们这样做

    class Enemy: GKEntity ...
    
    let agentComponent = AgentComponent()
        agentComponent.delegate = self
        agentComponent.radius = Float(texture.size().width * 0.3)
        addComponent(agentComponent)
    

    然后设置代表

    agentDidUpdate
    
    angentWillUpdate
    

    这些是一些很好的教程

    http://www.raywenderlich.com/119959/gameplaykit-tutorial-entity-component-system-agents-goals-behaviors

    http://code.tutsplus.com/tutorials/an-introduction-to-gameplaykit-part-1--cms-24483

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 2014-07-20
      相关资源
      最近更新 更多