Hi. I’m making an app that uses pixel art graphics, and I want to be able to place sprites on an exact pixel on the screen.
This works great on a non-Retina iPad. I use “noSmooth()” and “spriteMode(CORNER)” in set up, and set the position of a sprite to an exact coordinate. Then I scale everything by 4 (using “scale(4,4)”) at draw, and I get that nice, chunky, pixel-perfect art style I’m after.
On Retina iPad, it doesn’t go so well. I can use “scale(8,8)”, but because of the way Codea handles Retina, my alignments are now off by a factor of 2. A button that was 70 pixels from the left is now 140 pixels from the left.
One way to fix this is to set all my positions as something like “70/ContentScaleFactor” so on Retina iPads, where the ContentScaleFactor is 2, the alignments are halved (to 35, then doubled back up to 70).
That works, but I feel like that’s not particularly sensible code. Plus, I have to write that in every time I want to place a sprite.
Is there something I can to do to surpress Codea’s position doubling on a Retina device? Or a way to half the x and y values of everything at draw time?
Any ideas welcomed!
.@britishgaming perhaps I’m missing something, but shouldn’t you get the same result with the same code on retina and non-retina devices?
For example the following code draws the sprite in the exact same physical location and size on both retina and non-retina screens:
sprite("Tyrian Remastered:Bad Case", 50, 50)
Now I understand that in the retina case, the sprite will really be rendered twice its size and at x=100, y=100, but that will look identical to the non-retina version. That is, they will occupy the same physical area if you were to hold two iPads, retina and non-retina, next to each other.
Am I misunderstanding what you are trying to do? Do you want the exact same appearance on both retina and non-retina displays? In that case, the same code should produce the same result.
And just as a sanity check: you don’t have @2x graphics that are identical resolution to your non-@2x graphics?
Hey Simeon - ah, I think your sanity check was completely - and embarrassingly - correct.
When I imported my sprites I had the Retina box checked, which seems to be the cause of the trouble (the dimensions in the Edit Image window were halved). I re-imported, with Retina unchecked, and now it’s the exact same on both my iPad 3 and mini. Perfect.
Whoops! Thanks so much for your help.
Glad to have helped.
How is Codea on an iPad mini? I haven’t had an opportunity to try it, and was afraid some of the buttons might be too small.
I’d say it’s fine as it is! I’m only using it to test as a non-Retina device, but just had a fiddle and all the major buttons are easy to tap. Shouldn’t cause any problems at all.