1
votes

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!

2
in corona graphics 2.0 to set color use values 0 - 1 rather than 0 - 255 - Lukis
Thank you, but answer not resolve my problem - Kvazios
Your image link is broken. - Colonel Thirty Two
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
Thanks for answer, but nothing change (add 1 more image link if first broken) - Kvazios

2 Answers

3
votes

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.

1
votes

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.