newImageRect width and height parameters should be optional

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]

Is anyone listening? How can we get traction on this? I cannot embed file sizes in my code. Currently, I wrote my image loader to load the image twice — once to find out the size, a second time with newImageRect.

I’m worried this is a really bad idea.

Will someone at Corona please speak to this? [import]uid: 37366 topic_id: 19617 reply_id: 98648[/import]

Fortunately, Ansca released some really good news today:

http://blog.anscamobile.com/2012/04/kicking-it-up-another-notch/#more-14869

I hope to be able to breathe a sigh of relief after getting more transparency into their development process. [import]uid: 71767 topic_id: 19617 reply_id: 100324[/import]