Problem with Dynamic Image Selection

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