为什么覆盖我的SKSpriteNode子类的位置变量会减慢这么多?

时间:2014-08-14 03:55:07

标签: swift sprite-kit

Scratch中有一个名为penDown的酷函数,它会让你的精灵在从A移动到B时在屏幕上跟踪一些颜色的线。我想通过子类重新创建这种行为SKSpriteNode并在位置发生变化时收到通知。然而,这个简单的覆盖导致整个事情减慢了一吨(FPS从20减少到7只有两个精灵):

override var position : CGPoint {
    get {
        return super.position
    }
    set {
        super.position = newValue
        // Add this new point to the bezier path of the line so that I can trace it.
    }
}

为什么会这样?

1 个答案:

答案 0 :(得分:3)

在这种情况下,您应该使用property observers而不是覆盖getset

override var position : CGPoint {
    didSet {
        // Add this new point to the bezier path of the line so that I can trace it.
    }
}