Can I manually set display.imageSuffix to downgrade image?

We have the following in our config.lua, using imageSuffix scale that are similar to the recommended. The issue we are running into is that on some devices while the display Scale would mean that it would be using @2x or @4x images, but it’s obvious during testing that the device is sluggish handling the higher resolution images. 

 content = { width = 320, height = 480, scale = "letterBox", xAlign = "center", yAlign = "center", imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, },

So, we have been trying to see if it is possible for us to manually reset the imageSuffix down on those specific devices, basically do something like this in main.lua:

display.imageSuffix = "@2x"; -- for @2x -- or display.imageSuffix = nil; -- for @1x

Base on the testing we have done, it appears that manually setting to “@2x” works (and it seems to pick up the right images), but for some reason we can’t seem to set it to nil. It just ignores our attempt to set it.

My questions are:

  1. Is doing this OK? Or would it cause problems within Corona? Is there a better approach?

  2. How do I set it down to nil for @1x.

Just FYI. Another reason we are interested in this topic is that our app downloads a fair bit of visual assets once the user launches the app. This is a problem for some low-end Android devices that have very limited disk space. So one idea we are toying with is to download only the @1x asset, and downgrade that user’s screen to @1x to save on disk memory (even though the device screen would have normally called for @2x).

Appreciate any input!

Have you tried setting it to an empty string?

display.imageSuffix = "";

I did some more testing. I apologize, I misspoke earlier. As it turns out, it doesn’t matter what I set display.imageSuffix to, it is still picking up what config.lua tells it to pickup. 

In other words, if you are on iPad Retina, it doesn’t matter if I set display.imageSuffix to “@2x” or “”, it’ll still use @4x images.

So, maybe the solution is to put conditionals directly into config.lua and make sure it gets set to what’s desired in there? 

Ah yes sorry, iirc it’s a read only variable.

Let me try to understand the problem better.   What devices are you seeing the sluggish behavior on?  What resolutions are those screens.  Maybe we can tweak the math to get you better response on intermediate screens.  And just to clarify the current math that’s going on.

If a Portrait app’s screen is less than 480px wide it will use the normal un-suffixed file.   All iPhone 3 series phones fit this.

A portrait app on a screen that is 480px wide to 959px wide will use the @2x file.   All iPhone 4 and 5 series phones and non-Retina iPads fit here.

Any portrait screens 960px or wider gets the @4x images.  Only Retina iPads qualify.

For Landscape apps, we use the bigger number in the math, so:

 < 720px = Normal  (All iPhone 3 series phones)

720px - 1439px = @2x (All iPhone 4 and 5 series phones and non Retina iPads)

1440px > = @4x  (All Retina iPads)

Now since I can’t easily quote specs on every Android device out there, my Google Nexus 7 (at 800x1280) would use the @2x images (800px < 960px and 1280px < 1440px).  Hopefully you can use this chart with your device and see which ones it should be using. 

Now if you need to have devices that may be bigger than 960px wide or 1440px tall and you need them to use the @2x images but you still want the retina iPads to use the @4x images, you can tweak around with the 1.5 and 3.0 numbers to create the window you need.  You could even ad an @3x class of images to target devices that would be between the @2x and @4x (at the expense of a bigger app bundle).

You could even put some conditional tests in your config.lua to force certain devices to ignore the @4x completely.    In our first version of the Ultimate config.lua blog post (http://coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/), you can see how we use if statements and device checks to pick out specific configurations for that device.

Rob

Rob - 

   Thanks for the detailed response. There is a place in our app, where the user could switch between scenes quickly. As a consequence, we are loading/unloading a background JPG and a couple PNGs quickly. The issue we are running into (ironically), is that on older iPad3 (retina) devices, we noticed the app lagging during these transitions when using @4x, but it runs real smooth on @2x. Newer iPads are all fine. 

   So, we are considering downgrading to @2x for iPad3 only. Based on your description, it sounds like if we want to do that, we should just put the conditional into the config.lua file. We’ll give it a try. 

Thx!

Andrew 

Have you tried setting it to an empty string?

display.imageSuffix = "";

I did some more testing. I apologize, I misspoke earlier. As it turns out, it doesn’t matter what I set display.imageSuffix to, it is still picking up what config.lua tells it to pickup. 

In other words, if you are on iPad Retina, it doesn’t matter if I set display.imageSuffix to “@2x” or “”, it’ll still use @4x images.

So, maybe the solution is to put conditionals directly into config.lua and make sure it gets set to what’s desired in there? 

Ah yes sorry, iirc it’s a read only variable.

Let me try to understand the problem better.   What devices are you seeing the sluggish behavior on?  What resolutions are those screens.  Maybe we can tweak the math to get you better response on intermediate screens.  And just to clarify the current math that’s going on.

If a Portrait app’s screen is less than 480px wide it will use the normal un-suffixed file.   All iPhone 3 series phones fit this.

A portrait app on a screen that is 480px wide to 959px wide will use the @2x file.   All iPhone 4 and 5 series phones and non-Retina iPads fit here.

Any portrait screens 960px or wider gets the @4x images.  Only Retina iPads qualify.

For Landscape apps, we use the bigger number in the math, so:

 < 720px = Normal  (All iPhone 3 series phones)

720px - 1439px = @2x (All iPhone 4 and 5 series phones and non Retina iPads)

1440px > = @4x  (All Retina iPads)

Now since I can’t easily quote specs on every Android device out there, my Google Nexus 7 (at 800x1280) would use the @2x images (800px < 960px and 1280px < 1440px).  Hopefully you can use this chart with your device and see which ones it should be using. 

Now if you need to have devices that may be bigger than 960px wide or 1440px tall and you need them to use the @2x images but you still want the retina iPads to use the @4x images, you can tweak around with the 1.5 and 3.0 numbers to create the window you need.  You could even ad an @3x class of images to target devices that would be between the @2x and @4x (at the expense of a bigger app bundle).

You could even put some conditional tests in your config.lua to force certain devices to ignore the @4x completely.    In our first version of the Ultimate config.lua blog post (http://coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/), you can see how we use if statements and device checks to pick out specific configurations for that device.

Rob

Rob - 

   Thanks for the detailed response. There is a place in our app, where the user could switch between scenes quickly. As a consequence, we are loading/unloading a background JPG and a couple PNGs quickly. The issue we are running into (ironically), is that on older iPad3 (retina) devices, we noticed the app lagging during these transitions when using @4x, but it runs real smooth on @2x. Newer iPads are all fine. 

   So, we are considering downgrading to @2x for iPad3 only. Based on your description, it sounds like if we want to do that, we should just put the conditional into the config.lua file. We’ll give it a try. 

Thx!

Andrew