I have a simple subclass of SKCameraNode
that I called InteractiveCameraNode
. For now it's very simple: I need things to happen when my camera's position changes. Here is what I did:
class InteractiveCameraNode: SKCameraNode {
// MARK: - Properties
var enableInteraction = true
var positionResponders = [(CGPoint, CGPoint) -> Void]()
/// Calls every closure in the `positionResponders` array
override var position: CGPoint {
didSet {
if enableInteraction {
for responder in positionResponders {
responder(oldValue, position)
}
}
}
}
}
Since I might have multiple things happening when the camera moves, I have an array of closures that are called when the camera's position is changed. So far everything works perfectly except the didSet
observer does not get called if I move the camera using an action. If I use a constraint on the camera to make it track a node and then move that node with an action, it works. If I move the camera by hand, it works. Why won't it work with actions?