程序在GKAgent2D位置和SpriteKit位置之间混淆

时间:2015-12-17 11:25:24

标签: swift sprite-kit position gameplay-kit

我正在使用GameplayKit和Swift。在我的代理移动组件中,我正在运行agentWillUpdate:但是收到错误"无法调用类型' Float2'的初始化程序。使用类型'(CGPoint)的参数列表'"在确定位置的线上。

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'没有会员'职位。'

在下一个函数调用中,我得到了与原始函数相反的错误,#34;无法调用类型' CGPoint'使用类型'(vector_float2)'"的参数列表;

func agentDidUpdate(agent: GKAgent) {
        guard let spriteComponent = entity?.componentForClass(SpriteComponent.self) else {
            return
        }

    spriteComponent.node.position = CGPoint(position)
}

CMD点击CGPoint(位置)将我带到GKAgent2D。看来这两个位置"相互颠倒。任何想法如何纠正这个?

1 个答案:

答案 0 :(得分:2)

如果您不想在每次使用这些扩展程序时编写转换代码,那么您可以保留问题中的代码。

Set wb = Workbooks("A1.xls")