iPhone retina - coordinates issue?

I’m working on porting from the iPad to the Codea runtime on XCode and generally life is good - however, I seem to be seeing a issue where although the WIDTH and HEIGHT Are reported as 960x640 on iPhone retina, screen coordinates are still working on 480x320. Is this expected? Sorry if this if covered elsewhere, I couldn’t see it.

Thanks!

Nobody else gets this? :-S

One thing I use for this is to multiply the x and y positions by ratios based on the width and height of your screen.

For example, your width and height ratios

widthRatio = WIDTH/1024 --landscape
heightRatio = HEIGHT/768 --landscape

And then use it to set your positions like this:

sprite("Planet Cute:Character Boy",widthRatio*250,heighRatio*500)

Hope this answered your question!

That’s quite odd @Marsdaddy. Do you have a simple code snippet that demonstrates the issue? I will attempt to debug it.

Ok - I’ve just knocked up some test code and it seems the issue is that when I run the app in iPhone 5.1 as a retina device in the simulator, WIDTH and HEIGHT are still reported as 480 and 320 (landscape mode) —


supportedOrientations(LANDSCAPE_ANY)
spriteMode(CORNER)
textMode(CORNER)
displayMode(FULLSCREEN_NO_BUTTONS)

chkrecs = {}

function setup()
    fontSize(12)
    for my = 0,5
    do
        for mx = 0,5
        do
            cr = {}
            cr.good = true
            cr.x = 96*mx
            cr.y = 96 * my
            cr.height = 96
            cr.width = 96
            addChkRec(cr)
        end
    end
end


function addChkRec(r)
    table.insert(chkrecs,r)
end

-- This function gets called once every frame
function draw()
    background(0, 0, 0, 255)
 
    noFill()
    strokeWidth(1)
	stroke(15, 208, 15, 255)

    for k,v in pairs(chkrecs)
    do
        rect(v.x,(HEIGHT-1)-v.y-v.height,v.width,v.height)
    end
    fill(15,208,15,255)
    text("WIDTH = "..WIDTH.." HEIGHT = "..HEIGHT,0, HEIGHT-14)
end

That’s correct behaviour, @Marsdaddy. I thought you said that the WIDTH and HEIGHT were being reported as 960x640, which would be incorrect behaviour.

The WIDTH and HEIGHT on a retina iPad should be 1024x768, and a retina iPhone is 480x320.

WIDTH and HEIGHT represent the logical screen size — not the size of the underlying pixel buffer. This is intentional so you can write the same code and have it perform in exactly the same way on retina and non-retina devices. On retina devices it will look sharper, and any @2x images you have will be loaded automatically instead of their lower resolution counterparts.

To get the actual screen size for any device, you would use:

ACTUAL_WIDTH = WIDTH * ContentScaleFactor

ACTUAL_HEIGHT = HEIGHT * ContentScaleFactor

But I’d recommend against this sort of coding.

Yes that makes sense@Simeon - so if I draw a point at 32,32 I assume that on retina, that’s actually a block of 2x2 pixels, but as far as codea is concerned, that’s just one pixel.

One other question - does this apply to image objects as well? So, if I have an image that is 96x96 actual pixels (an @x2), I should consider it to be 48x48 when doing things like a copy operation out of it? I mean image to image when carving up an image.

Thanks, and keep up the good work!