Image scale distorted when created after screen rotation

When I create an image after the device’s orientation has changed (i.e., starting from portrait and changing to landscape, or starting from landscape and switching to portrait), the scale of the image will be distorted, as shown in the attached image (starting orientation on left, changed orientation on right). If the device is switched back to its starting orientation again, newly created images will have the correct scale.

On the left is the image in the starting orientation, and on the right is the image after the device has been rotated.

The thing that’s really getting to me is that I’ve only observed this issue on one device (2012 Nexus 7). Images are displayed correctly on the simulator, an iPad mini, two other Android tablets, and four Android phones.

Sample project which reporoduces the issue as is follows. The image is a 100x100 px square.

main.lua

display.setDefault( "background", 80/255 ) squareImg = display.newImageRect("icon1.png", 300, 300) squareImg.x = 250 squareImg.y = 250 local function onOrientationChange( event ) if squareImg ~= nil then display.remove(squareImg) squareImg = nil end squareImg = display.newImageRect("icon1.png", 300, 300) squareImg.x = 250 squareImg.y = 250 end Runtime:addEventListener( "orientation", onOrientationChange )

config.lua

application = { content = { scale = "none", fps = 60, } }

build.settings

settings = { orientation= { default = "portrait", supported = { "portrait", "portraitUpsideDown", "landscapeRight", "landscapeLeft", } }, }

 

If anyone could at least point me in the right direction on how to diagnose this problem, I’d greatly appriciate it.

Hi @corona026,

Try specifying a width and height in your config.lua “content” table, and change the “scale” setting to something other than “none”… I suggest either “letterbox” or “zoomEven”. You’ll really want to do this regardless, so you can eventually take advantage of dynamic image selection.

This guide gives all of the specifications:

http://docs.coronalabs.com/guide/basics/configSettings/index.html

Best regards,

Brent

Thanks for your response! Unfortunately, there are a number of design reasons why for this particular application I cannot use dynamic scaling.

According to this, display.contentScaleX and display.contentScaleY should always be 1 for the above code sample, but for some devices it is not. The messy but working solution to this bug is to multiply every pixel-dependent measurement in your project by display.contentScaleX or display.contentScaleY as needed.

Hi @corona026,

Can you provide more details why dynamic image selection (not scaling) is not workable for you? If you don’t do this, your app will either look bad on Retina/HD devices, or you’ll be scaling down really large assets onto smaller devices, causing a potential performance hit (or worse, the textures simply won’t load because the device can’t handle them).

Brent

Hi @corona026,

Try specifying a width and height in your config.lua “content” table, and change the “scale” setting to something other than “none”… I suggest either “letterbox” or “zoomEven”. You’ll really want to do this regardless, so you can eventually take advantage of dynamic image selection.

This guide gives all of the specifications:

http://docs.coronalabs.com/guide/basics/configSettings/index.html

Best regards,

Brent

Thanks for your response! Unfortunately, there are a number of design reasons why for this particular application I cannot use dynamic scaling.

According to this, display.contentScaleX and display.contentScaleY should always be 1 for the above code sample, but for some devices it is not. The messy but working solution to this bug is to multiply every pixel-dependent measurement in your project by display.contentScaleX or display.contentScaleY as needed.

Hi @corona026,

Can you provide more details why dynamic image selection (not scaling) is not workable for you? If you don’t do this, your app will either look bad on Retina/HD devices, or you’ll be scaling down really large assets onto smaller devices, causing a potential performance hit (or worse, the textures simply won’t load because the device can’t handle them).

Brent