Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How to scale images to full screen on all devices, i want to use %

The method I've seen so far is to define pixels

image_variable_name = display.newImage( "testimage.jpg", 100, 300 )

I want to do something like

image_variable_name = display.newImage( "testimage.jpg", 100%, 100% )

But that won't work, I want something like fluid CSS, the image will maintain the size no matter what is the size of the screen. Is it possible?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Try using newImageRect() instead of newImage()

image_variable_name = display.newImageRect("testimage.jpg", display.contentWidth, display.contentHeight)
--then you have to center it: 
image_variable_name.x = display.contentWidth / 2
image_variable_name.y = display.contentHeight / 2
share|improve this answer

Actually Corona uses feature called dynamic scaling so it let you working within same virtual size - 320х480. You can even have different assets for different scale factors.

share|improve this answer

Use display.newImageRect(), except unlike display.newImage(), you now have to enter the width and height of the image you are feeding in (the actual file). This will now scale automatically.

Also, if you ever switch to landscape mode for your default orientation, make sure your config.lua still has the fields width and height as if you were in portrait mode. Its a weird gotcha.

Here's how I present a background picture which takes up the full screen of a landscape mode 1280 x 720 display (Galaxy S3):

menuBg = display.newImageRect( "images/bg.png", 1280, 720 )
menuBg:setReferencePoint( display.CenterLeftReferencePoint )
menuBg.x = 0
menuBg.y = display.contentHeight/2

Setting the reference point is of personal preference, so play with that yourself.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.