The constructor for newImageRect
presently looks like this:
object = display.newImageRect( [parentGroup,] filename [, baseDirectory] width, height )
I’m having trouble discerning why it’s necessary to specify width and height during this call. This requirement adds needless complexity to a project, and limits the usefulness that can be achieved by a modular code base.
The whole point of newImageRect
is that the method will search for appropriately-dimensioned images, based on the current display content scaling, by appending user-specified file suffixes to filename
to see if such files exist. As such, newImageRect
will already know how scaled the chosen image is.
For example, assume that the following config.lua
is used on an iPhone 4:
application =
{
content =
{
width = 320,
height = 480,
scale = "letterbox",
imageSuffix =
{
["@480x720"] = 1.5,
["@640x960"] = 2,
},
},
}
Also assume that the following images exist within a project:
Square.png -- 100 x 100, @1x
Square@480x720 -- 150 x 150, @1.5x
Square@640x960 -- 200 x 200, @2x
When the following code is executed:
image = display.newImageRect( "Square.png", 100, 100 )
the provided width and height are unnecessary. That’s because when Corona chooses to load “Square@640x960.png
”, newImageRect
already knows that the image is scaled twice as big. Therefore, image
should be scaled automatically by 1 / 2
.
Similarly, when Corona chooses to load “Square@480x720.png
”, newImageRect
already knows that the image is scaled one-and-a-half times as big. Therefore, image
should be scaled automatically by 1 / 1.5
.
I can achieve the same effect with newImage
and contentScaleX/Y
, but then that just really messes up Box2D integration.
Requiring the developer to know and track image sizes, and hard-code these measurements into their apps, is really just a bad practice and unnecessary hurdle. [import]uid: 71767 topic_id: 19617 reply_id: 319617[/import]