What's The Best Solution For X And Y Position

Guys, i just realized if we change device in corona simulator (like from iphone 4 to ipad) then the object position will also change on the screen. Something like:

player.x = 40 player.y = 400

won’t look the same in different devices. I want to make them look great in different devices, what’s the best solution for the objects position? [import]uid: 114765 topic_id: 22235 reply_id: 322235[/import]

If you are scaling up it doesn’t exactly change position; have a read on dynamic scaling.

For this a great thing to do is to look at the Ghosts VS Monsters sample code; it shows an app that looks almost the same on iPad and iPhone and looks great :slight_smile:

Peach [import]uid: 52491 topic_id: 22235 reply_id: 88587[/import]

I’m guessing it is because iPad or them Androids has some extra space that are beyond the width and height that you specify in your config file.

If you want your object to be positioned a certain amount of value from the screen border you need to add something like this

[lua]-- BEFORE –
player.x = 40
player.y = 400

– AFTER –
local trueX = display.screenOriginX
local trueY = display.screenOriginY
player.x = trueX + 40
player.y = trueY + 400[/lua]

I hope this was what you were talking about, otherwise just ignore my post [import]uid: 114118 topic_id: 22235 reply_id: 88606[/import]

hi there,

tbh i dont understand in ghosts vs monsters where’s the specific line that discuss about this…because i see the ghostObject.x and ghostObject.y is just using basic numbers

as for trueX and trueY, i think it doesn’t really change much. I still have an object that looks totally far in iPad (but looks OK in other devices)

i wonder if there’s special code to show different position for different devices like if device == ipad then bla bla and if device == nexus one then bla bla? [import]uid: 114765 topic_id: 22235 reply_id: 88621[/import]

The easiest way is to position everything relative to the center of the screen. Create vars for xCenter and yCenter. So it looks like this:

-- Instead of   
player.x = 40  
  
-- You have:  
player.x = xCenter - 150 -- (or whatever)  
  

Then you don’t have to worry about screen origins at all. [import]uid: 40137 topic_id: 22235 reply_id: 88632[/import]

Sorry, that wasn’t completely accurate. You also need a var for the screen origin of each axis. originX, originY.

On the iPad in landscape mode display.screenOriginY is -20. On the iPhone it’s 0. (Assuming you’re using 480x320 in your settings).

So you would position your object relative to the center of the screen and add the origin to it:

player.y = yCenter - 100 + originY  
  

This will put it the same distance from center on every device. [import]uid: 40137 topic_id: 22235 reply_id: 88634[/import]

You need to read through this page for how to set Dynamic Content Scaling in your config.lua file.

http://developer.anscamobile.com/content/configuring-projects

Essentially, you set the content size to say 480 x 320, and it will scale up to larger screens where necessary, how it scales will depend on whether you select letterbox, zoomStretch or zoomEven.

Your x and y references are in relation to the content size, not the screen size, so there’s no need to have different values for different devices. [import]uid: 93133 topic_id: 22235 reply_id: 88635[/import]

hi guys,

i have read about dynamic content scaling. in fact i have tried to compare my config.lua with the ghost vs monster one and everything looked very similar and im still wondering why several of my objects look different in iPad (but yeah it looks perfect in other devices including android ones).

of course i use letterbox. i have tried zoomeven and it made it worse. Not sure about the others, what are the other options?

as for the originX and originY, i understand that but what to fill in local originX and local originY, really?

I put originX = display.contentWidth / 2

but apparently it doesn’t work? [import]uid: 114765 topic_id: 22235 reply_id: 88645[/import]

originX = display.screenOriginX  
originY = display.screenOriginY  
xCenter = display.contentCenterX  
yCenter = display.contentCenterY  
  

[import]uid: 40137 topic_id: 22235 reply_id: 88652[/import]

How do they look different, stretched/squashed, or just in the wrong place?

letterbox should give you a 320 x 480 stage, scaled up to 640 x 960 with black borders taking up the rest of the 768 x 1024 space on an iPad. Make sure you use newImageRect and have @2x images.

zoomStretch will fill the whole screen, so on an iPad objects will look wider (in portrait mode).

zoomEven will fill as much of the screen as possible without distorting the aspect ratio (i.e. circles stay as circles and don’t become ovals)

For some of my games I used zoomStretch because it didn’t matter that things were stretched a little on iPad, but my current project has a clock which I didn’t want to become oval-shaped so I’m using letterbox. I made the background big enough to cover all screen sizes, so on an iPhone some of it will be offscreen but on an iPad it fills the black borders. I also have a few text objects which change y position if it’s on iPad to use the extra space. [import]uid: 93133 topic_id: 22235 reply_id: 88654[/import]

@mmathias6410: it works mate thanks

@nick_sherman: i created floor that i want to put at the very bottom part of the screen but it went up a bit in iPad. However things work well with mmathias6410 trick [import]uid: 114765 topic_id: 22235 reply_id: 88669[/import]