我是GameplayKit
的新手,因为大多数人都有自己的生命,并且一直试图弄清楚以下内容。
我有一个SKNode *enemy
已经从SpriteKit
获得了相当多的工作和定制,从动作到风格,习惯等。我的问题是:
GKAgent2D
,以便它控制这个节点的运动?我知道你必须创建一个GKComponent
并用一个Sprite Node表示这个组件,或许有一个选择的纹理。但我想知道是否有办法使用内置的"控制运动" GameplayKit
在现有节点上提供的方法。如果答案是"否"请说出来并解释为什么?我感谢任何帮助。谢谢!
答案 0 :(得分:1)
你的敌人是GKEntity吗?如果它不相信你不能添加GKComponent。
如果您的敌人是GKEntity而不是简单地添加GKComponent作为代理人。否则你将不得不改变你的敌人类别,使它成为一个GKEntity。
苹果在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://code.tutsplus.com/tutorials/an-introduction-to-gameplaykit-part-1--cms-24483