Need some assistance understanding coordinates in Corona

Hey everyone. I started messing around with Corona yesterday (fresh off the boat!) but I’ve already knocked out a test game based on a tutorial, and figured things out pretty easy. I took the “Attack of the Cuteness” tutorial game, finished it, and ended up adding some extra stuff to it when all in said and done. Got it loaded on my Galaxy S5 and it’s playable.

Anyway, I’ve started on a “from-scratch” game just to screw around but I’m having a lot of trouble with finding a good resources on understanding coordinates and what to use in my functions.

I know 0,0 is top-left, the X-axis is left to right and Y-axis is top to bottom. I’m familiar with centering objects (display.contentCenter) but in the game I’m attempting now, I’ve managed to set up an image sheet with frames, and I’m using an individual frame for my “hero.” I want to bring him from off-screen at a specific part of the background image.

I can just sit there and keep putting values in until it looks right, but I’m trying to figure out an easy way to determine what coordinates are where. Through trial-and-error I sort of figured out the X-axis total is around 500, and the Y-axis is around 300. But is there any way in Corona Simulator to show coordinates where the mouse is located? Or something similar?

For reference here’s the code I’m using:

function spawnHero() local hero = display.newImage( sheet, 1 ) hero.xScale = .75 hero.yScale = .75 hero.x = centerX + 50 hero.y = centerY + 50 transition.to (hero, {time=1000, x=centerX , y=centerY}) end

The hero.x and hero.y I’m going to end up placing outside the screen boundaries, and the x= and y= in the transition.to will be a bit off center.

Hi @c.merchant10,

Good to hear that your experience is positive so far. When considering coordinates, it’s necessary to understand the Corona “content space” and scale mode. The content space can be considered basically like a rectangular canvas which will fit on the device screen. Within that content area, coordinates are relative, so for example 0,0 will always be the top-left of the content area, but not necessarily the absolute top-left of the device screen.

Similarly, the size of the content area will correlate to your coordinates. For example, if your content area is 320 wide by 480 tall, the bottom-right corner will be 320,480. Center would be 160,240. And so forth.

Here are some resources on the topic:

http://docs.coronalabs.com/guide/basics/configSettings/index.html

http://youtu.be/RwVlzJtQWd8

Take care and best of luck,

Brent

Thanks for the reply! Between your reply and the article you linked to I think I’m making sense of it a bit more.

I’ve read that article, but it didn’t really click until now. So my content space is 320x480 (which I can use for coordinates, but reversed since the device is horizontal), and by using the letterbox scaling option it’ll maintain the aspect ratio on different devices, even if the content doesn’t completely fill the screen. And I can find those settings in the config.lua file!

That’s definitely helpful - thank you!

Hi @c.merchant10,

Yes, “letterbox” is a good choice, although “zoomEven” or “adaptive” are valid options too. I’m glad I caught one thing however: your content area should always be “short side, long side”, even if you’re designing the app for horizontal/landscape orientation. For example, it should be like 320x480, not 480x320. The actual orientation is controlled otherwise by setting which orientations are possible for the app.

Best regards,

Brent

Hi @c.merchant10,

Good to hear that your experience is positive so far. When considering coordinates, it’s necessary to understand the Corona “content space” and scale mode. The content space can be considered basically like a rectangular canvas which will fit on the device screen. Within that content area, coordinates are relative, so for example 0,0 will always be the top-left of the content area, but not necessarily the absolute top-left of the device screen.

Similarly, the size of the content area will correlate to your coordinates. For example, if your content area is 320 wide by 480 tall, the bottom-right corner will be 320,480. Center would be 160,240. And so forth.

Here are some resources on the topic:

http://docs.coronalabs.com/guide/basics/configSettings/index.html

http://youtu.be/RwVlzJtQWd8

Take care and best of luck,

Brent

Thanks for the reply! Between your reply and the article you linked to I think I’m making sense of it a bit more.

I’ve read that article, but it didn’t really click until now. So my content space is 320x480 (which I can use for coordinates, but reversed since the device is horizontal), and by using the letterbox scaling option it’ll maintain the aspect ratio on different devices, even if the content doesn’t completely fill the screen. And I can find those settings in the config.lua file!

That’s definitely helpful - thank you!

Hi @c.merchant10,

Yes, “letterbox” is a good choice, although “zoomEven” or “adaptive” are valid options too. I’m glad I caught one thing however: your content area should always be “short side, long side”, even if you’re designing the app for horizontal/landscape orientation. For example, it should be like 320x480, not 480x320. The actual orientation is controlled otherwise by setting which orientations are possible for the app.

Best regards,

Brent