sprite-kitpixelsktilemapnode

SKTileMapNode Pixel to Pixel Aligning


I am working on a tilemap game with Apple's newish SKTileMapNode. The pixels on my tiles do not match up with the pixels on the phone display. My scale mode is set to .resizeFill. My tile's sizes are correctly labeled as 64x64 and each tile's texture's image is sized correctly. Notice the horizontal and vertical lines, especially near the tree trunk

I am using a camera that is a child of the gray circle in the attached image. I believe that the camera will create a pixel to pixel view of the screen size being used and match the resolution, but I am not sure that I can trust this. How can I get my pixels to align correctly to avoid this.


Solution

  • It turns out that SpriteKit's SKTileMapNode really likes assets to be optimized for all resolutions. This fixed my pixel alignment problem entirely. While this may seem obvious, I originally added @1x files in order to use an optimized texture atlas. It took more research to discover how to add different resolutions to a texture atlas.

    Since it is different than normal atlases (appending ".atlas" to a folder of images), I will describe how to do so here

    Go to the assets.xcassets folder and click "New Sprite Atlas." In here drag in all @2x and @3x images. Delete the [asset-name].atlas folder if you had one before, as this will not support different resolutions natively.

    From here on, the atlas can be accessed just as the original [asset-name].atlas folder was accessed in code.