Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Have a problem, when i set background in Corona SDK by this code or any other:

local background = display.newRect(0,0, display.contentWidth ,display.contentHeight)
background:setFillColor( 255, 255, 255 )  

(width may be hardcoded), the simulator then show me this image:

http://apikabu.ru/img_n/2014-02_3/7mw.jpg

One more same picture, if link above is broken

http://tinypic.com/r/2vmy3qr/8

What i do wrong ? Why x,y coordinates wrong ? If i try to put image or text coordinates be wrong too.

One more for those who don't understand question: In this picture we have coordinates left=0, top=0 and text out of display

http://tinypic.com/r/34grcao/8

And here coordinates left=50, top=10, and now we see text, but why left-top corner is not left=0, top=0 ?

http://tinypic.com/r/259jqfb/8

Thanks for answers!

It may be an issue with config.lua. Try to run the code without config.lua. If it works fine, then please post the code inside config.lua. – Krishna Raj Salim Feb 11, 2014 at 17:21

You are setting the location of the rect to 0, 0 -- and the "anchor point" for that rect is the center of the object. So the rect on the screen as shown is correct -- the center is at 0, 0.

To center the rect on the screen, just modify the x and y properties:

background.x = display.contentCenterX
background.y = display.contentCenterY

That should center the rect on the screen.

Corona SDK used to create objects with a top-left anchor point which then automatically shifted to a center anchor point. Recently that was changed so they're now created with a center anchor point.

Please, read top question now, i add some stuff! Thanks you! This problem not with background only. With all coordinates. – Kvazios Feb 12, 2014 at 8:04 if you set x and y, you set it to anchor point, not whole image. in graphics 2.0 anchor is default at 0.5, 0.5 (center of image), so if you set x and y for an image to 0, 0 your anchor (center of image) will be at 0, 0. To set anchor to left top point, set anchorX=0, anchorY=0 – Lukis Feb 12, 2014 at 8:33

You can also use this in your main.lua file

display.setDefault("background", 255, 255, 255, 1)

It will set default background color for all screens.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.