Screen coordinates in iPhone 3G and Retina

I’m a bit confused about how Corona handles coordinates across different devices with differing screen resolutions. For example, if I’m displaying something on Retina that is outside the screen coordinates of a 3G phone, how am I supposed to convert the coordinates for the 3G phone.

e.g.

-- Assume this is for a Retina display  
local myObject = display.newImageRect("image.png", 50, 50)  
myObject.x = 600  
myObject.y = 700  

How should I write the code so that it will display correctly on a 3G device?

Like this?

local deviceModifier = 0  
  
-- Assume this is for a Retina or 3G display only  
if (ThisDeviceIsRetina) then -- ThisDeviceIsRetina is made-up code, just assume it returns True if the Device is Retina  
 deviceModifier = 0  
else  
 deviceModifier = 0.5  
end  
  
local myObject = display.newImageRect("image.png", 50, 50)  
myObject.x = 600 \* deviceModifier  
myObject.y = 700 \* deviceModifier  

Is that the sort of approach to take or am I missing a feature of Corona that does this automagically? [import]uid: 26769 topic_id: 13166 reply_id: 313166[/import]

There are lots of ways of handling things but could I encourage you to check out the Ghosts VS Monsters sample code? It can be built for multiple devices and it shows you how to handle every aspect of this kind of thing that you are likely to encounter along the way. [import]uid: 52491 topic_id: 13166 reply_id: 48320[/import]

Ok, thanks for the tip :slight_smile: [import]uid: 26769 topic_id: 13166 reply_id: 48322[/import]

I downloaded GvM and had a quick look at one of the level.lua files. The code uses display.newImageRect as my example above, but when setting the x/y coordinates it doesn’t use any modifier that I could see.

The config.lua specifies the app as a 320 X 480 resolution, i.e. iPhone 3G. If I am running the app on a Retina device at 640 x 960, does Corona automatically set the screen x/y coordinates for me?

e.g.

-- Assume the config.lua file specifies a resolution of 320 x 480 -- On a 3G phone this will display at 50, 50 -- On a Retina phone will it automatically display the image at 100, 100? local myObject = display.newImageRect("image.png", 50, 50) myObject.x = 50 myObject.y = 50 [import]uid: 26769 topic_id: 13166 reply_id: 48342[/import]

@lordmooch, check out these articles:

http://blog.anscamobile.com/2010/11/content-scaling-made-easy/
http://blog.anscamobile.com/2011/01/dynamic-image-resolution-made-easy/

They should help you understand what’s happening. [import]uid: 26 topic_id: 13166 reply_id: 48357[/import]

Thanks for the info :slight_smile: [import]uid: 26769 topic_id: 13166 reply_id: 48377[/import]