2D CCCamera Follow

WitlockWitlock USMember

I have spent hours on trying to perfect this.
I've tried setting values to Camera.TargetInWorldspace and Camera.CenterInWorldspace after player movement.
it somewhat works, but there's slight loss of quality for pixel art making it seem like the camera is doing something wrong even though I'm moving by pixels. I get a 90% perfect result by doing this with a semi random Z value, but something is missing.
The tiles on the tile map are either overlapping each other by 1 pixel or a bit stretched and the character is not pixel perfect.
I have also tried using Camera.UpdatePerspectiveCameraTargetBounds, but the way the Z value of CenterInWorldspace affects the view is giving me a headache.
What is the correct way to move the camera along with the player?
PS: Moving the background is not an option.


  • WitlockWitlock USMember
    edited December 2015

    There actually seems to be a scaling issue instead.
    The map (tiled) is pixel perfect in windowed mode at native resolution, however if I try the same thing in full screen with CCSceneResolutionPolicy.ShowAll it becomes a bit distorted.
    The native resolution is 640x360, full screen is 1920x1080.
    CCSprite seems to do fine, but the tilemap (no antialiasing) is messing up.

  • WitlockWitlock USMember

    It was pointed out to me that the Tiled example for CocoSharp has a similar problem:

  • RamiTabbaraRamiTabbara AUMember, Xamarin Team Xamurai

    Hi Sander,

    Can you please provide a snippet of how you're attempting to move the camera. In general, if you're attempting to pan the camera for a 2d game, then you'll need to modify both the Target and Centre of the camera.

    Finally, let us know what platform you're targeting and whether you're observing these artefacts on both the simulator and device.

  • WitlockWitlock USMember
    edited December 2015


    This is how I move the camera and it seems to work well in full screen mode:

            Camera.TargetInWorldspace = new CCPoint3(X,  Y, 0);
            Camera.CenterInWorldspace = new CCPoint3(X, Y, 512);

    X and Y are the players coordinates and this is ran every time the player moves.

    Right now it seems like the problem I'm having has something to do with how CocosSharp manages Tiled tiles.

    I assume everything would be fine for regular 2D, but for scaled pixel art this is a major issue.
    It feels like CC believes the window is slightly smaller than 1920x1080 and pushes some tiles together.

    PS: Can you please explain where the 512 for Z is coming from and what is the logic behind it?

    I'm currently only targeting windows and I can only confirm this happens on Windows 10.

  • RyanCamarattaRyanCamaratta USMember

    If you have any updates on this please let me know. I have almost the exact same setup as you, I've been working on this for months and it's so annoying not getting it to work. I just want the character sprite in the center of the screen with the camera following the movement of the sprite , so I can have a big map, with the character in the center of a smaller portion of the map.

    Think SNES-era Final Fantasy or Gameboy Pokémon games. Seems like it should be a simple thing for a 2D game engine to have as I'd imagine this is something alot of people want to implement with it. I'm just so tired of screwing with this, I don't want to build more of the game or assets until I can get the camera following working correctly so this project's been on hold for a long time now.

Sign In or Register to comment.