[英]What is the difference between SKNode's position property and GKAgent2d's position property
[英]Link SKNode to GKAgent2D?
我是GameplayKit
新手,因為大多數人都有使用期限,並且一直在努力找出以下內容。
我有一個SKNode *enemy
,它已經從SpriteKit
了大量的工作和自定義,從動作到樣式,習慣等。 我的問題是這樣的:
GKAgent2D
以便它控制該節點的運動? 我知道您必須創建一個GKComponent
並用一個Sprite節點(可能具有一定的選擇紋理)表示該組件。 但是我想知道是否有一種方法可以使用GameplayKit
在已經存在的節點上提供的內置“控制運動”方法。 如果答案為“否”,請這么說並解釋為什么? 感謝您的幫助。 謝謝!
您的敵人是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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.