I've been working on adding zooming functionality to my project via an SKCameraNode
and a pinch recognizer. My camera node is overlooking the mainMap
node that contains my game and I would like to have limited zoom capability.
In my function handler for pinches I have this code:
func zoomView(recognizer: UIPinchGestureRecognizer){
let currentScale = (mainScene.camera?.xScale)!
let futureScale = (currentScale * recognizer.scale)
if futureScale > 1.1 || futureScale < 0.5{
recognizer.scale = 1.0
return
}else{
mainScene.camera?.setScale((mainScene.camera?.xScale)! * recognizer.scale)
}
recognizer.scale = 1.0
print("currentScale: \(currentScale)")
print("recognizerScale: \(recognizer.scale)")
print("scaleFactor: \(futureScale)\n")
}
I've looked at many somewhat similar questions but they don't have this exact issue. When the scale approaches the bound values and becomes values such as 1.09812164306641
, I tend to have a stuttering effect on the zoom as it seems to not be able to get to the exact boundary value.
Does anyone have advice on how to avoid this behavior? Most helpful would be an explanation of how to get the zoom to behave more naturally where on reaching a limit it does the little bounce effect customary to IOS applications. Really any coherent explanation on how to use cameras with smooth zooming would be much appreciated!
Thank you