Reputation: 126
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!
Upvotes: 1
Views: 5070
Reputation: 321
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.
Upvotes: 1
Reputation: 331
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.
Upvotes: 3