2016-03-02 45 views
0

我是新來GameplayKit因爲大多數給出了其壽命,並一直試圖弄清楚以下..將SKNode鏈接到GKAgent2D?

我有一個已經被賦予了相當多的工作和定製的,從運動風格的SKNode *enemy,習慣等全部來自SpriteKit。我的問題是這樣的:

  • 我該如何「鏈接」我的敵人節點到GKAgent2D,以便它可以控制此節點的移動?

我知道你必須創建一個GKComponent並用一個Sprite節點來表示這個組件,這個Sprite節點可能帶有一定的選擇紋理。但我想知道是否有一種方法可以使用GameplayKit在已有節點上提供的內置「控制運動」方法。如果答案是「否」,請說出來並解釋爲什麼?我感謝任何幫助。謝謝!

回答

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://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

一些好的教程