Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Sprite Kit display @2x images from atlas at correct size?

When a project only has @2x images because it only targets retina display devices, atlas Sprite Kit atlas gets the scale wrong with the RGBA8888_COMPRESSED setting to use with PVR textures. RGBA8888_PNG (the default) sometimes works ok.

Before switching to atlas, I had all @2x images in a group and loaded them with:

sprite = [SKSpriteNode spriteNodeWithImageNamed:@"theImage.png"];

No problems. Correct size.

Now with atlas and RGBA8888_COMPRESSED, I get the SKTexture and the image is way too large. Exact same nodes and configuration. Only using SKTexture from atlas instead.

Why does this happen?

like image 617
openfrog Avatar asked Jan 02 '14 18:01

openfrog


1 Answers

The atlas image should have the @2x suffix but not the files contained in it.

Won't work:

atlas.png contains [email protected]

Correct usage:

[email protected] contains theImage.png

I'm not even sure Sprite Kit supports PVR textures to begin with. Perhaps try confirming that your setup works with PNG and then export as PVR and try that.

When you do that, be sure to clean your project (Xcode: Project -> Clean) and remove the app from the device/simulator (this step is crucial!) otherwise the bundle will still contain the PNG atlas image and you may be fooled into thinking that PVR works because Sprite Kit may actually load the PNG atlas that still exists in the bundle if you don't remove it and clean your build.

like image 166
LearnCocos2D Avatar answered Oct 13 '22 04:10

LearnCocos2D