obj.fill vs obj:scale() vs display.newImageRect

Hey community! Just wondering what are the negative effects/benefits/performance of these three approaches for display image objects:
 

local img=display.newRect(0,0,50,50) img.fill={type="image",filename="test.png"} -- versus -- local img=display.newImage("test.png") img:scale(0.5,0.5) -- versus -- local img=display.newImageRect("test.png",50,50)

Hi @eja,

I would not recommend #2, unless for some reason you don’t want to support dynamic image selection.

#1 (fill method) could be useful if you want to change the image (change the fill) dynamically in code. #3 would not allow this, because it’s an actual image, versus an “image-filled rectangle”, so to dynamically change the image in #3, you’d need to recreate the object entirely (or set it up as a sprite object and change the frame).

#1 could also be useful if you want to do a pattern fill, and tinker around with the repeat mode, repeat orientation, scale, etc.

That being said, #3 is definitely the easiest for basic images, so I don’t want new users to think they should go with #1, unless they know why/how to use that method!

Performance-wise, I don’t think #1 and #3 would be much different, if at all.

Hope this helps,

Brent

Thank you brent, that’s the answer I was looking for! I must say, I love the support here at corona!

Hi @eja,

I would not recommend #2, unless for some reason you don’t want to support dynamic image selection.

#1 (fill method) could be useful if you want to change the image (change the fill) dynamically in code. #3 would not allow this, because it’s an actual image, versus an “image-filled rectangle”, so to dynamically change the image in #3, you’d need to recreate the object entirely (or set it up as a sprite object and change the frame).

#1 could also be useful if you want to do a pattern fill, and tinker around with the repeat mode, repeat orientation, scale, etc.

That being said, #3 is definitely the easiest for basic images, so I don’t want new users to think they should go with #1, unless they know why/how to use that method!

Performance-wise, I don’t think #1 and #3 would be much different, if at all.

Hope this helps,

Brent

Thank you brent, that’s the answer I was looking for! I must say, I love the support here at corona!