Possible dynamic image resolution bug?

In my project directory I have a 200x200 png called "image.png" and a 100x100 png called "image@ip3.png", along with the following config.lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
application =
{
    content =
    {
        width = 640,
        height = 960,
        scale = "letterbox",
        
        imageSuffix =
        {
            ["@ip3"] = 0.5
        }
    }
}

You want to omit the @ip3 suffix from the original image so your files are named like this:

The original image size (to appear on iPhone 3G/S and below) shouldn't have a suffix. Then, you should add this to your config:

["@ip4"] = 2

That tells your app that anything with the suffix of @ip4 will be double the size of the same-name image without that suffix.

Then, here's where I see you major problem is with your code above. When you call display.newImageRect(), you need to specify the dimensions of the ORIGINAL file, not the @ip4 file:

display.newImageRect( "image.png", 100, 100 )

You also need to specify the location of that new display object (by setting it's x and y values), because with display.newImageRect, it no longer defaults to the center of the screen (like display.newImage). Instead, it defaults to the origin (center of the image) being at the top-left corner of the screen.

jon,

Thanks for the explanation.

Just a quick question: Does the base image always have to be the one with the lowest resolution? i.e., The values in imageSuffixes have to be >= 1?

Well 1 isn't necessary because that is the default scale for an image. So should be useful for anything 2 and higher.

Actually, come to think of it, it's still not making sense. Note that in my config.lua, I've specified 640x960 as my reference resolution, and the original image.png is 200x200. So, when I do display.newImageRect("image.png", 200, 200), I actually am specifying the original resolution of the image -- and, in fact, that's the one that gets loaded when the resolution of my device matches my reference resolution, just as we'd expect.

When I'm using a device resolution of 320x480 (half my reference resolution), I would expect image@ip3.png to be loaded, since it was given a scaling factor of 0.5 in imageSuffixes (and it is, in fact, half the size of the original image.png). But that's not what happens. Instead, the original 200x200 image.png always gets loaded, and image@ip3.png is ignored.

I know it's an easy fix: Just use the lowest resolution as my reference resolution, and then provide suffixes for scaling factors greater than 1. Just seems a little inconsistent that I can't do things in the opposite direction (i.e., specify a higher resolution as my reference resolution, and then provide suffixes for scaling factor less than 1). Ah well, no biggie...

I'm interested in the answer to this, too. For reasons related to my art production pipeline I would like to use the iPhone 4 as the "native" resolution and scale everything else off of that. But I ran into the same problem trying to use a scale of 0.5 in my config for iPhone 3; The lower resolution assets were never used on the device. Which leads to another question, what's the downside of iPhone 4 resolution assets being used on iPhone 3, which Corona seems to be forcing? All the examples on this site assume the original resolution is the iPhone 3.

@ XenonBL, I think one downside would be that the iPhone 4 has more texture memory than an iPhone 3... 2048x2048 vs 1024x1024. So if your iPhone 4 images were greater than 1024x1024, it would work fine on the iPhone 4, but would break on the iPhone 3.

I also ran into a similar problem when I was using a larger "native" resolution... maybe Ansca assumed that everyone would use the smallest resolution as native and always scale up. If so, sounds like a bug (or they need to clarify this in their documentation).

David, I think the downside you mention is exactly why XenonBL, like me, is trying to use a fractional scale factor in imageSuffixes. It would allow us to create half-res versions of our images to be used on devices such as the iPhone 3, while explicitly targeting the iPhone 4 (or iPad or whatever). Or am I missing something?

@Hookflash, right, that's why I was trying to get it to work as well. In my case, it was fine for me to redo my code so it assumed the iPhone 3 as the default resolution. Where I think it could be a problem, though, is if you want to position something based on iPhone 4 or iPad coordinates. If the iPhone 3 is the default, then you'd only be able to position items on those coordinates, losing half of the precision available.

David,

Yes, the loss of precision is my worry as well. Also, I have to wonder what happens when something like a transition defined within iPhone 3 cooridinates gets scaled up to, say, iPhone 4 resolution. Does it become jerky, moving in 2 pixel increments?

Good questions, Hookflash! How do we draw attention to this discussion so Ansca staff can answer them?

@DavidBFox, Yeah, I'm avoiding using 2048x2048 textures altogether, even for iPhone 4, just so I don't run into problems on less-capable platforms. My goal is to make my cross-platform development as painless as possible, which is what led me to Corona in the first place.

The precision issues you raised hadn't occurred to me, so before I retool everything to use iPhone 3 as the base platform I'd love to hear the official word from someone at Ansca on the subject. Is the fact that Corona ignores scaling factors like 0.5 a bug, or is this intended behavior? (in which case, the docs. should be updated to reflect this)

Ideally, I'm hoping this is a bug since, for me, the least painful path is to develop natively for iPhone 4.

Also, I've just started reworking my app to use spritesheets and am wondering if those will "just work" with the whole dynamic content scaling scheme. If I create a 2X version of a spritesheet graphic will the original 1X lua data for that sheet be sufficient or does a 2X version of the data need to be generated as well?

Has this been answered? I would LOVE to know this:

If I develop for iPhone at 320 x 480, and position a display object on the screen at location x=15, y=4 what happens in the iPhone4 version (with 640 x 960 resolution)?

Does corona translate all visual placement, creating a 320 x 480 'neo-pixel' screen out of the iPhone4's native 640 x 960 resolution? So that while the code coordinates from above (x=15, y=4) the object is actually placed at the pixel coordinates x=30, y=8?

I little verbal verification of how it works will save me a lot of time trying to test it out on a few devices... especially devices I don't have. Thanks!

I've been doing everything with the iPad as the "native" resolution and now, after hours of trying, it turns out I can't set imageSuffix to 0.5? WHAT? This is not in the docs. Please Ansca, fix this!

So this it's my 3:44AM workaround, config.lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if system.getInfo("model") == "iPad" then
  application =
{
        content =
        {
            width = 768,
                height = 1024,
                scale = "zoomEven",
                xAlign = "center",
        yAlign = "center",
 
        },
}
else
  application =
{
        content =
        {
            width = 768,
                height = 1024,
                scale = "zoomEven",
                xAlign = "center",
        yAlign = "center",
        imageSuffix =
        {
            ["@50"] = 0.4,
        },
 
        },
}       
end

I stumbled on the same issue here. Thanks for this post I found cmontesino's workaround. Thanks bro.

I really wish this would be corrected....

views:2283 update:2012/2/10 9:26:24
corona forums © 2003-2011