Problem with Dynamic Image Selection

Hi,

I don’t know why my image selection does not work properly.

This is my config.lua file:

application =

{

content =

    {

    width = 640,

     height = 960,

     scale = “letterbox”,

     imageSuffix =

        {

            

            ["@320"] = 0.5    

        },

      fps = 60

    }

}

In my project folder I have (*.png  *@320.png) and (*.jpg  *@320.jpg) files.

The problem is only the *@320.* files are loaded for any device I try in the simulator, with the exception of the iPhone4/5 where it works as it should and it selects the high resolution assets by default.

To be clear, when I select iPad retina, iPad, kindle HD, etc … in the simulator, the app loads the @320 assets by default.

This does not make sense for me.

Thanks for your answer,

Ignacio

P.S.: I’m using the latest public release.

P.S.2: I’m not using widgets in my ‘main.lua’ file but I’m using ‘native.newTextField’ and ‘native.newTextBox’

Hi @ignacioric,

Usually the best way to “debug” this kind of behavior is to print the imageSuffix value and check what is returned when you test different simulated devices in the Simulator.

[lua]

print( display.imageSuffix )

[/lua]

If you’re not getting the proper image set loading for some device, you’ll need to adjust your scale value (the 0.5 you’re using) or create more cases to make sure it’s picking the correct images.

Best regards,

Brent

Hi Brent,

Thank you for the answer.

I use a ‘caveman’ method to know if I’m loading the right set of images, it consist in placing a watermark on some key images so I know which ones I’m loading :slight_smile:

My problem is that my default (640x960) set of images are not loading in devices like the iPad, iPad Retina, Kindle fire HD, etc… to the contrary the smaller ones (320x480) are getting loaded (with the exception of the iPhone 4/5, that match exactly the resolution written inside the ‘config.lua’).

I don’t know what I’m missing or doing wrong.

Best regards,

Ignacio

Hi Ignacio,

On the devices which aren’t doing what you expect (iPad, iPad Retina, etc.), what is the printed value of display.imageSuffix ?

Hi Brent,

In the devices where it suppose to load the @320 set, the console prints: @320

In the devices where it suppose to load the default set of (640x480), the console prints: @320

In the iPhone 4 the console prints: nil 

In the iPhone 5 the console prints: nil

So on iPad, for example, it’s printing “@320” but it’s displaying the base image (image.png) and not image@320.png?

No, it’s printing @320 and it’s displaying the image@320.png

P.s: Thank you very much for your time!

I’m confused… what do you want it to do? Are the @320 images actually the “smaller” ones? And your “default” (non-suffixed) are larger in size?

Brent

Yes, the @320 images are the smaller ones, and my default (non-suffixed) are the larger ones.

That’s why I’m puzzled that when I switch to a device with higher resolution (iPad, iPad retina, Kindle fire HD), Corona does not stick with the default (non-suffixed) images, but chooses the smaller ones instead.

My config.lua file looks like this, if that helps

application =

{

content =

    {

    width = 640,

     height = 960,

     scale = “letterbox”,

 

     imageSuffix =

        {

            

            ["@320"] = 0.5    

        },

 

      fps = 60

    }

}

Hi Ignacio,

Consider calculating your suffix scale values using some formulas like those below, which I borrowed from one of my projects. Of course you’ll need to adjust things (and the calculations/divisions) based on your content scale, not 704x1024.

Brent

[lua]

application = 

{

   content = 

   {

      fps = 60,

      width = 704,

      height = 1024,

      scale = “letterbox”,

      xAlign = “center”,

      yAlign = “center”,

      imageSuffix =

      {

         – [""] = 0.8,

         --Galaxy / K.Fire1 / Nook | 600(deviceWidth)/704 = 0.8523

         --iPhone4 / iPod-4 / iPhone5 | 640(deviceWidth)/704 = 0.9091

         --iPad1/iPad2 | 1024(deviceHeight)/1024 = 1.0000

         --Samsung S3 | 720(deviceWidth)/704 = 1.0227

         --K.FireHD / Nexus7(1) | 800(deviceWidth)/704 = 1.1363

         --iPhone6 | 750(deviceWidth)/704 = 1.0653

         ["-3"] = 1.5

         --Samsung S4 / iPhone6 Plus | 1080(deviceWidth)/704 = 1.5341

         --K.FireHD-9" / Nexus7(2) | 1200(deviceWidth)/704 = 1.7045

         --iPad3 | 2048(deviceHeight)/1024 = 2.0000

         --Nexus10 | 1600(deviceWidth)/704 = 2.2727

      }

   }

}

–print(1/display.contentScaleX, 1/display.contentScaleY)  --put this into main.lua to return value for device

[/lua]

Brent

Hi and good morning from Spain,

Thank you very much for your response! Because finally … the project works as it should!

The magic line you wrote that gave me the clue was:

 – [""] = 0.8,

Now, I’ve changed my ‘config.lua’ file to this:

application =

{

content =

    {

    width = 640,

     height = 960,

     scale = “letterbox”,

     imageSuffix =

        {

            [""] = 0.9,

            ["@320"] = 0.5    

        },

     fps = 60

    }

}

Everything works as I want, and Corona loads the default (non-suffixed) set of assets for my target resolutions above (640x960).

I haven’t seen anything in the documentation regarding this ‘[""]’ to change the behaviour of the default set, so I think It could be great if it gets included(if it’s not already there!).

Thanks again for your continued interest in solving this question. You have saved me a lot of work! Because I wanted to remove several set of images for my Android build to keep the .apk as small as possible and I could not find the easy/smart way to do it.

Kind Regards,

Ignacio Ric

Happy to help Ignacio. The reason that most people don’t need that [""] = x suffix is because their lower-quality images are the “default” ones (no suffix added). Then, for higher resolutions, they append a suffix on there like @2x or @4x. In your case, you are doing it in reverse, where the lower-quality images actually have a suffix appended, and the high-quality images do not. Thus, you need to tell Corona that, above a divisor of 0.9, it should use the non-suffix images (which the empty quotes does).

Take care,

Brent

Hi @ignacioric,

Usually the best way to “debug” this kind of behavior is to print the imageSuffix value and check what is returned when you test different simulated devices in the Simulator.

[lua]

print( display.imageSuffix )

[/lua]

If you’re not getting the proper image set loading for some device, you’ll need to adjust your scale value (the 0.5 you’re using) or create more cases to make sure it’s picking the correct images.

Best regards,

Brent

Hi Brent,

Thank you for the answer.

I use a ‘caveman’ method to know if I’m loading the right set of images, it consist in placing a watermark on some key images so I know which ones I’m loading :slight_smile:

My problem is that my default (640x960) set of images are not loading in devices like the iPad, iPad Retina, Kindle fire HD, etc… to the contrary the smaller ones (320x480) are getting loaded (with the exception of the iPhone 4/5, that match exactly the resolution written inside the ‘config.lua’).

I don’t know what I’m missing or doing wrong.

Best regards,

Ignacio

Hi Ignacio,

On the devices which aren’t doing what you expect (iPad, iPad Retina, etc.), what is the printed value of display.imageSuffix ?

Hi Brent,

In the devices where it suppose to load the @320 set, the console prints: @320

In the devices where it suppose to load the default set of (640x480), the console prints: @320

In the iPhone 4 the console prints: nil 

In the iPhone 5 the console prints: nil

So on iPad, for example, it’s printing “@320” but it’s displaying the base image (image.png) and not image@320.png?

No, it’s printing @320 and it’s displaying the image@320.png

P.s: Thank you very much for your time!

I’m confused… what do you want it to do? Are the @320 images actually the “smaller” ones? And your “default” (non-suffixed) are larger in size?

Brent

Yes, the @320 images are the smaller ones, and my default (non-suffixed) are the larger ones.

That’s why I’m puzzled that when I switch to a device with higher resolution (iPad, iPad retina, Kindle fire HD), Corona does not stick with the default (non-suffixed) images, but chooses the smaller ones instead.

My config.lua file looks like this, if that helps

application =

{

content =

    {

    width = 640,

     height = 960,

     scale = “letterbox”,

 

     imageSuffix =

        {

            

            ["@320"] = 0.5    

        },

 

      fps = 60

    }

}