Auto Scaling on iPhone4

I know many other have posted on this but I have read there posts and I am now more confused that before.

This is my config.lua

application =
{
content =
{
width = 320,
height = 480,
scale = "zoomEven",

imageSuffix =
{
["@2"] = 2,
},

},
}

This is my code (stripped down to test the idea)
local menuBackgroundImg = display.newImageRect("iphone.png", 640, 960)

Now thing is if I run on simulator I get the correct image / image substitution (as I have made them two coloured square) but unless I put in 640,960 (as show) then they do not scale to fill the screen on the sim in iphone 4 or 3g (which seems strange as the project is 320,480 and the box is 320x480).

I am confused as I though from this:-
http://developer.anscamobile.com/content/configuring-projects#Dynamic_Image_Resolution

We were supposed to use the coordinates system of 320 x 480 to place assets etc and then just have the hi res versions substituted so not to have to layout using 480 x 960

I am confused as I have laid out my app and art at 320x480 but can easily export at x4 res but do I make the width and height in config.lua iphone 4 and have to reposition things (e.g. optioned set to be 10x10 pixel from top left) or do I leave as is and use image substitution if so why do I have to make imageRect 640 x 960 even to run on iphone 3
??????????
????

Your statement:
local menuBackgroundImg = display.newImageRect("iphone.png", 640, 960)

Should be:
local menuBackgroundImg = display.newImageRect("iphone.png", 320, 480)

Corona will use the 2x resolution image (iphone-@2.png) on iPhone4 and iphone.png image on iPhone3.

-Tom

Thanks Tom,

No that's my point I know or believe we are supposed to be using 320 x 480 (the referencing that for possitioning this etc).

But it doesn't work for me for some reason. I get the image at a quarter of the screen it only fills the screen if I use 640 x 960.

BUT it is sutsituting the image because I made the two different Images for two resolutions two different colours to prove it was swapping between the iphone.png and iphone@2.png.

So I am at a loss.

It sounds like the settings in your config.lua file is not scaling the display to 320x480 for the iPhone4. I'm not sure why it doesn't work on iPhone3 which is 320 x 480.

I'm a little confused about what problems you are seeing. Is your display not working at 320x480 or is the problem your images are not working at 320x480?

This is how I would troubleshoot the problem:
I would create a newRect that is 320 x 480 (which should fill the screen) and test it on the simulator, iPhone3, and iPhone4. With the settings in your config.lua, it should fill the screen in all three cases.

Then, load a 320x480 image (without the 2x image) and see what that does. It should show up full screen on a iPhone3 and iPhone4 (because of scaling).

If the newRect fills the screen but the image doesn't, I would say that your image is not really 320x480. If the newRect fills the screen on iPhone3 but not on iPhone4, then the problem is in your config.lua file.

That's all I can say without seeing the code and the images involved.

-Tom

Right this
dummy = display.newRect(0, 0, 320, 480 )
dummy:setFillColor(2550,0,0)

and this

local menuBackgroundImg = display.newImage("iphone.png")

Both fill the screen on iphone 3 and 4 in simulator, but this:-

local menuBackgroundImg = display.newImageRect("iphone.png", 320, 480)

Causes the image to be draw at 1/4 of the screen so it is not even scaling up the bitmap regardless of substitution when used within a newImageRect (In fact as explained earlier situation takes place the bitmap called iphone@2.png is only displayed when simulator is in iphone4 but in all situations it's drawn at 1/4)

Thanks for help in advance.

The problem has something to do with your 2x image, either in the naming or the resolution of the image. Have you confirmed that it's 640 x 960?

You are running your app in portrait mode, right?

What happens if you remove the reference to the 2x image in your config.lua file? It should default back to your iphone.png file instead (which should fill the screen).

If you run the DynamicImageResolution sample code shipped with Corona SDK, does that work on your iPhone 4?

What version of IOS are you running on your iPhone4?

I'm wondering if there is a image naming issue. Our sample code use -x2.png at the end of the high res file name. Try that if the sample code works on your iPhone4.

-Tom

Hi Tom,

I have figured out the issue its all done to these lines.

myImage.x = display.contentWidth / 2
myImage.y = display.contentHeight / 2

With them it works.

I think what must be happening is that it is placing the images centre at the top left which if you think about it would make it look like it is only filling 1/4 of the screen when in effect what is happening is that the remaining 3/4 are off the visible screen.

Which I though was odd as I though that all objects automatically used their own centre reference point and when placed on screen defaulted to alligning with the screens centre reference point etc.

From your description it sounded like you were seeing the full image but it was 1/4 the size. Now it sounds like the image was centered at x=0, y=0, so you were seeing only part of the image (the rest was off-screen).

Were you setting the image to 0,0 or was that the default position?

The display.newImageRect is different from display.newImage because you don't specify the x,y values in the creation of the object. All other objects (except newCircle) are created with the x,y pointing to the top left corner and once created, the x,y points to the center of the object.

I'm glad this issue is resolved. I think it shows we need to add more information to our on-line documentation.

Thanks,
-Tom

The DynamicImageResolution sample works in the Corona simulator but not on my iPad or iPad2. Why?

views:2020 update:2011/10/1 9:04:19
corona forums © 2003-2011