I have added UIPinchGestureRecognizer to my scene.view to scale my content. I actually scale the parent node where all my visible contents reside. But I have problem though with scaling point. The thing is node scale from the lower-left corner. It's definitely not what I want. Do I have to write lots of code to be able to scale from the point where pinching occurs? Could you please give some hints as to what way to follow.
相关问题
- Scaling of the point sprites (Direc3D 9)
- Scaling png font down
- Change a SKPhysicsBody's body shape
- SKSpriteNode created from SKTexture(data:size:) is
- bodyWithEdgeLoopFromRect not working in landscape
相关文章
- How do you use SKTextureFilteringNearest with SKTe
- Can I add a border to an SKSpriteNode, similar to
- How to zoom list item from center of pinch
- Subclassing SKShapeNode with Swift
- CGPointMake in Swift
- UIWebView scaling page so that there is no need fo
- Modify a repeating task sequence while running
- SpriteKit - Mouse Snaps to Center On Sprite Drag
In Swift 4, my
SKScene
adds theUIPinchGestureRecognizer
to the view but passes handling of the pinch gesture off to one of itsSKNode
children that is created in the scene'sinit()
, due to some reasons not relevant here. Anyhow, this is ninefifteen's answer from the perspective of what s/he calls_mySkNode
. It also includes a little code to limit the zoom and does not use the convenience functions listed at the bottom of his post. The@objc
part of the declaration allows the function to be used in#selector()
.Here is what is in my
SKScene
:And this is the relevant section in my SKNode:
Can't zoom I don't know why but the main problem is those SKT_INLINE. I've googled them and didn't found anything about 'em... The problem is when I copy/paste them in my project the compiler tells me I have to add an ";" right after them. I wonder if that's the reason that I can zoom.
I have been working on the same problem and my solution is shown below. Not sure if it is the best way to do it, but so far it seems to work. I'm using this code to zoom in and out of an SKNode that has several SKSpriteNode children. The children all move and scale with the SKNode as desired. The anchor point for the scaling is the location of the pinch gesture. The parent SKScene and other SKNodes in the scene are not affected. All of the work takes place during recognizer.state == UIGestureRecognizerStateChanged.
The following are helper functions that were used above. They are from the Ray Wenderlich book on Sprite Kit.
I have translated ninefifteen's solution for Swift and Pinch Gestures. I spent a couple days trying to get this to work on my own. Thank goodness for ninefifteen's Obj-C post! Here is the Swift version that appears to be working for me.