I'm making a SpriteKit game and I'm trying to get an SKCameraNode to follow the player node. However, when I access the position property of the player node after using an SKAction to move it, the position after running the action is the same as the position before running it. Here is my scene code:
func updateMap(playerX: Int, playerY: Int) {
player.coordinates = CGPoint(x: highlightedTile.tileX, y: highlightedTile.tileY)
camera?.position = player.position
}
and the code from my player class:
var coordinates: CGPoint {
didSet{
let moveAction = SKAction.moveTo(CGPoint(x: (coordinates.x) * 64 - 64, y: (coordinates.y) * 56 - 47), duration: NSTimeInterval(2.0))
self.runAction(moveAction)
}
}
SpriteKit does not update the position property of the player node until the action is complete. Therefore I want to wait until the animation has completed before updating the camera position. How can this be done?