我正在使用GameplayKit和Swift。在我的代理的移動組件中,我正在運行agentWillUpdate:但在位置已確定的行上出現錯誤「無法爲類型爲'Float2'的類型爲'(CGPoint)'的參數列表調用初始化程序」。程序越來越困惑GKAgent2D位置和SpriteKit位置
MoveComponent: GKAgent2D, GKAgentDelegate {
init(...)
func agentWillUpdate(agent: GKAgent) {
guard let spriteComponent = entity?.componentForClass(SpriteComponent.self) else {
return
}
position = float2(spriteComponent.node.position)
}
節點位置是好的(我已經測試了這個打印)。當我通過「位置」點擊CMD時,我被帶到SpriteKit的位置屬性,而不是GKAgent2D的屬性。當我嘗試引用屬性與agent.property時,調試器告訴我'類型'GKAgent'的值沒有成員'的位置。'
在未來的函數調用中,我得到了同樣的錯誤我原來的一個反向,「不能調用類型‘CGPoint’初始化器與類型的參數列表‘(vector_float2)’」
func agentDidUpdate(agent: GKAgent) {
guard let spriteComponent = entity?.componentForClass(SpriteComponent.self) else {
return
}
spriteComponent.node.position = CGPoint(position)
}
CMD點擊通過CGPoint(位置)將我帶到GKAgent2D。看起來這兩個「職位」是相互顛倒的。任何想法如何糾正這一點?
這是一個我用XCode編寫過的錯誤,它有時會對它正在尋找的屬性感到困惑,並會選擇它認爲最好的屬性。你有沒有嘗試做一個完整的清理版本(CMD + SHIFT + ALT + K)? – Knight0fDragon
謝謝。我試過一個乾淨的版本,但仍然有錯誤 –
看看這個,也許它會幫助你http://stackoverflow.com/questions/31343504/how-to-convert-between-vector-float2-and-cgpoint – Knight0fDragon