Positioning objects in the scene when using newImageRect.

Hi,

When we are using newImageRect, we don’t certainly know what resolution our game will run. So how we can make sure that position objects are in corners because if we increase and decrease pixels, it will vary on devices with different resolutions.

Thanks. [import]uid: 206803 topic_id: 34398 reply_id: 334398[/import]

You seem to make a lot of threads, could probably just compress into one. Anyways…

Regardless of how you setup config.lua, 0,0 should be the top left corner of the screen on your current device. Just keep in mind this:

local object = display.newImageRect("image.png", 52, 34) -- currently TopLeftReferencePoint object.x = 32 -- now CenterReferencePoint

After you make any object you need to manually set the reference again (or just keep it at center.) Always set the reference BEFORE changing X/Y

[code] – Correct, the x will be set per your ref point setting
object:setReferencePoint(display.TopLeftReferencePoint)
object.x = 32

– Wrong, the new ref point here only counts to actions afterward
object.y = 48
object:setReferencePoint(display.BottomLeftReferencePoint)[/code]

When you need display objects to stretch across the screen, use variables. ie: if you want something that’s 400px wide to always be relatively that wide on other displays you could use math.round(display.contentWidth \* (400/480) ) [import]uid: 41884 topic_id: 34398 reply_id: 136699[/import]

You seem to make a lot of threads, could probably just compress into one. Anyways…

Regardless of how you setup config.lua, 0,0 should be the top left corner of the screen on your current device. Just keep in mind this:

local object = display.newImageRect("image.png", 52, 34) -- currently TopLeftReferencePoint object.x = 32 -- now CenterReferencePoint

After you make any object you need to manually set the reference again (or just keep it at center.) Always set the reference BEFORE changing X/Y

[code] – Correct, the x will be set per your ref point setting
object:setReferencePoint(display.TopLeftReferencePoint)
object.x = 32

– Wrong, the new ref point here only counts to actions afterward
object.y = 48
object:setReferencePoint(display.BottomLeftReferencePoint)[/code]

When you need display objects to stretch across the screen, use variables. ie: if you want something that’s 400px wide to always be relatively that wide on other displays you could use math.round(display.contentWidth \* (400/480) ) [import]uid: 41884 topic_id: 34398 reply_id: 136699[/import]