Displaying background image

I am a new to corona sdk. I want to display a full  backgroung picture that fills my phone in simulator. But i cant find help.

the code is:

local background = display.newImage(“background,png”)

what this does is i get small image in top left cornor of the the screen…I am facing difficulties in the very first phase of learning corona

plz do help

By default Corona positions display objects based on their center. Since you haven’t set a .x and .y, they are 0, 0. Your object is centered on 0, 0.  Simly set the .x and .y to where you want it. If you want it centered:

local background = display.newImage(“background,png”)

background.x = display.contentCenterX

background.y = display.contentCenterY

Rob

Hey! Like what @Rob mentioned: Set your object in the center… But try this instead.

local background = display.newImageRect( "background.png", 320, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY

Good Luck!

I’d rather use this if you want a fullscreen though it stretches your image so add an “@2x” version of your image.

local background = display.newImageRect( "background.png", display.contentWidth, display.contentheight ) background.x = display.contentWidth/2 background.y = display.contentheight/2

or

Change your anchor X and Y

local background = display.newImageRect( "background.png", display.contentWidth, display.contentheight ) background.anchorX = 0 background.anchorY = 0

By default Corona positions display objects based on their center. Since you haven’t set a .x and .y, they are 0, 0. Your object is centered on 0, 0.  Simly set the .x and .y to where you want it. If you want it centered:

local background = display.newImage(“background,png”)

background.x = display.contentCenterX

background.y = display.contentCenterY

Rob

Hey! Like what @Rob mentioned: Set your object in the center… But try this instead.

local background = display.newImageRect( "background.png", 320, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY

Good Luck!

I’d rather use this if you want a fullscreen though it stretches your image so add an “@2x” version of your image.

local background = display.newImageRect( "background.png", display.contentWidth, display.contentheight ) background.x = display.contentWidth/2 background.y = display.contentheight/2

or

Change your anchor X and Y

local background = display.newImageRect( "background.png", display.contentWidth, display.contentheight ) background.anchorX = 0 background.anchorY = 0