Reputation: 75
I am trying to make the game, but I stuck on camera movement with player. I need to set max camera and player x position, but I get infinite movement to the right or left.
I was tying to use override func didFinishUpdate()
override func didFinishUpdate() {
cam.position.x = player.position.x
}
and here I tried to set world size
worldNode = SKSpriteNode()
worldNode?.size.width = backGroundImage.size.width
self.addChild(worldNode!)
Please help
Upvotes: 2
Views: 376
Reputation: 3995
func keepPlayerInBounds() {
if player.position.x < frame.minX + player.size.width/2 {
player.position.x = frame.minX + player.size.width/2
}
}
put this in update, then add the other 3 boundaries (the above is the left boundary)
this also assumes player.anchorPoint is 0.5
Upvotes: 2