Presently, when Content Scaling is specified using scale = "zoomStretch"
in config.lua
, there exists the possibility that display.contentScaleX
and display.contentScaleY
will have different values. In this case, it would be useful if the user could specify, via a new setting in config.lua
, which content scaling axis will be evaluated in order to determine whether to use higher resolution images as per the Dynamic Image Resolution feature.
For example, display.contentScaleX
might be 0.5
but display.contentScaleY
might be 0.25
. In this case, should higher resolution images be used? Some developers might prefer lower resolution graphics to be used. Others might prefer higher resolution graphics to be used only if the content scale settings meet certain criteria. A new config.lua
setting “scalingAxis
” would control this behavior.
scalingAxis
could have one of the following values:
contentWidth would use the content scale of the screen width, as determined by current device orientation.
contentHeight would use the content scale of the screen height, as determined by current device orientation.
contentScaleMin would use the content scale that is the lesser of display.contentScaleX
and display.contentScaleY
.
contentScaleMax would use the content scale that is the greater of display.contentScaleX
and display.contentScaleY
.
screenWidth would use the content scale for the screen width, unaffected by device orientation.
screenHeight would use the content scale for the screen height, unaffected by device orientation.
screenResMin would use the content scale for the X/Y axis with the lesser resolution.
screenResMax would use the content scale for the X/Y axis with the greater resolution.
This is fairly trivial to implement, as I’ve done for my own code as follows:
[blockcode]
function getDisplayHeight()
return roundNumber (
display.viewableContentHeight / display.contentScaleY, 2 )
end
function getDisplayWidth()
return roundNumber (
display.viewableContentWidth / display.contentScaleX, 2 )
end
function getDisplayScale()
local scalingAxis = getConfigSettingForScalingAxis()
if ( scalingAxis == nil ) then
scalingAxis = defaultScalingAxis
end
local scalingFactor = 1
local height = getDisplayHeight()
local heightScale = display.contentScaleY
local width = getDisplayWidth()
local widthScale = display.contentScaleX
if ( scalingAxis == “screenResMax” ) then
if ( height > width ) then
scalingFactor = heightScale
else
scalingFactor = widthScale
end
elseif ( scalingAxis == “screenResMin” ) then
if ( height < width ) then
scalingFactor = heightScale
else
scalingFactor = widthScale
end
elseif ( scalingAxis == “contentScaleMax” ) then
if ( heightScale > widthScale ) then
scalingFactor = widthScale
else
scalingFactor = heightScale
end
elseif ( scalingAxis == “contentScaleMin” ) then
if ( heightScale < widthScale ) then
scalingFactor = widthScale
else
scalingFactor = heightScale
end
elseif ( scalingAxis == “contentHeight” ) then
scalingFactor = heightScale
elseif ( scalingAxis == “contentWidth” ) then
scalingFactor = widthScale
elseif ( scalingAxis == “screenHeight” ) then
if ( ( system.orientation == “landscapeLeft” ) or
( system.orientation == “landscapeRight” ) )
then
scalingFactor = heightScale
else
scalingFactor = widthScale
end
elseif ( scalingAxis == “screenWidth” ) then
if ( ( system.orientation == “landscapeLeft” ) or
( system.orientation == “landscapeRight” ) )
then
scalingFactor = widthScale
else
scalingFactor = heightScale
end
end
return scalingFactor
end
function getDynamicScale()
return 1 / getDisplayScale()
end
– Thanks to http://lua-users.org/wiki/SimpleRound
function roundNumber( num, idp )
local mult = 10^( idp or 0 )
return math.floor( num * mult + 0.5 ) / mult
end
[/blockcode] [import]uid: 71767 topic_id: 18739 reply_id: 318739[/import]