IOS: Implementing a User-Driven Zoom Camera with Sprite Kit

I have a working 2D platformer that wraps the Sprite Kit. To implement the world of scrolling , I follow the Apple tutorial in my extended scene processing documentation : my scene contains the world; The world contains all the nodes, including the camera node.

Now I am creating a level editor, and this works fine too. Here is my problem: I can’t understand how to “scale the camera input and output” in the level editor.

I searched and found this stack overflow question . Using the Smick answer, I was able to implement scaling behavior that turned out to be correct, but caused incorrect node sprites (in my editor, when increasing or decreasing, I can no longer select sprites).

How do I scale the camera? Or, how do I adjust the position of an object after a zoom operation?

If you have a tested solution, I have all the ears. I mean ... eyes. Yes.

+3
source share
1 answer

Well, this is what happens when you ignore answers with a lower score. Repeating the same question I contacted above, I tried to answer JKallio and got his job.

(, ):

:

- (IBAction)pressedZoomIn:(id)sender
{
  CGFloat newZoom = [EditorState zoom] - 0.1f;
  [EditorState setZoom:newZoom];
  [EditorState currentScene].size = CGSizeMake([EditorState currentScene].size.width * newZoom, 
                                               [EditorState currentScene].size.height * newZoom);
}
- (IBAction)pressedZoomOut:(id)sender
{
  CGFloat newZoom = [EditorState zoom] + 0.1f;
  [EditorState setZoom:newZoom];
  [EditorState currentScene].size = CGSizeMake([EditorState currentScene].size.width * newZoom, 
                                               [EditorState currentScene].size.height * newZoom);
}

"" , , .

+3

All Articles