2

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.

Alec O
  • 1,697
  • 1
  • 18
  • 31
  • Make sure you round your position, there may be errors where your position is really 10.5, so it will appear at pixel 11. when you may want it at 10 – Knight0fDragon Apr 20 '17 at 19:40
  • 1
    That may be the magic answer. I can't believe I didn't see something so simple. I will test when I get home. – Alec O Apr 20 '17 at 20:09
  • to round the camera position solved the problem for me. thanx for the simple and useful advice – Bernd May 27 '19 at 22:10

1 Answers1

0

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.

Alec O
  • 1,697
  • 1
  • 18
  • 31