iossprite-kitanchorpoint

Moving the scene: SKAction animation or anchorPoint in update method?


My game is based on two screens (A & B) side by side, but the device screen can only display one of them at a time.
A is for example at position (0, 0) and B is at (320, 0)

I tried two solutions to switch from A to B:

Now, if I want to go from A to B with an animation, these two solutions must be adapted:

These two solutions works (despite a linear SKAction::timingMode does not render a linear translation properly), but I wonder which is the best in term of optimization, and elegance. Documentation is welcomed ;)

EDIT:

Apparently, my question is not clear (maybe due to my english level).

In few words, my question is: What exactly are the best practices for scrolling a scene?


Solution

  • I am surprised (0, -1) doesn't throw a huge exception. According to the docs you get a range from 0 to 1. This could cause issues in the future. See the docs here

    Changing your position sounds like a more elegant way of handling it. however changing it to negative -320 in a span of 1/10th of a second is rather quick and could explain why it looks funny. Also if you aren't making sure you are only calling that once it will look really odd. I would make sure that it is only getting called once and maybe using a bool to toggle if it should be moved instead of checking a position.

    If you are going back and forth a lot from one screen to another this might be an ok solution. However if you are looking to scale this to a much larger map where you are going to transition several times to new screens I would recommend a different approach all together. Like creating a new node off screen when you need it and transition a parent node then pop the old node off.

    I hope that helps.

    Edit

    Now that the question is "what exactly are the best practices for scrolling a scene".

    I would recommend what LearnCoco2D mentioned in the comment and what I eluded to in my original answer.

    In the past I have built my Scenes in a similar fashion and have handled the scene position based on the player position in the update loop. I was able to keep the player in the center of the screen as he walked around the map. Might be getting off subject, but that is what I found the best practice for handling scrolling a scene from my experience. The project I am working on can be viewed here

    I hope that answers your question.