jts
jts

Reputation: 33

SpriteKit SKCameraNode unable to animate zoom

for my iOS game using SpriteKit. I have a camera node in the scene.

var cam = SKCameraNode()
self.camera = cam

//THIS WORKS, view zoomed out to 2x
cam.setScale(2)

//I want to animate the zoom out, but this doesn't work
let zoomOutAction = SKAction.scaleTo(2, duration: 1)
cam.runAction(zoomOutAction)

Upvotes: 1

Views: 532

Answers (2)

Simone Pistecchia
Simone Pistecchia

Reputation: 2842

I fixed it, simply added the line: self.addChild(cam)

var cam = SKCameraNode()
cam.position = CGPointMake(size.width/2, size.height/2)
self.addChild(cam)
self.camera = cam

Upvotes: 2

Duncan Oliver
Duncan Oliver

Reputation: 59

Don't know if you're still having this problem, but hopefully this helps…

I had a similar problem with a moving a SKCameraNode with a moveToY SKAction. Even though setting the position would work, either directly or in a runBlock SKAction, the action wouldn't work. It would start, but jump back to the original position after the end. Using runAction(withKey:) made it run to completion. Try something like:

cam.runAction(zoomOutAction, withKey:"zoom")

Hope this was useful.

Upvotes: 0

Related Questions