Hello,
how to put an width and an height properties for the sprite ?
I only find by using the addEventListener-sprite, and changing the width and height at each frame, like below :
local sp=display.newSprite( g,sheet, sequence ) sp:addEventListener( "sprite", function(ev) sp.width=40 sp.height=40 end )
when I try by writting
sp.width=40 sp.height=40
this only change the width and height of the first sprite only, not all.
Did you have a better method ?
Thanks.
I always use obj:scale().
thanks it’s work.
Why did it works better than changing widh and height ?
No idea since I can’t see the internals, but I’m going to assume that width and height are transient values that are re-updated each time the sprite source image changes, where as current scale factor is permanent until changed.
Actually this is the answer:
For images, the returned value is the original bitmap width, including any transparent area.
https://docs.coronalabs.com/api/type/DisplayObject/width.html#overview
Since you are effectively changing this on each frame change, the value is getting updated.
Note / Word of Advice:
I always treat width and height as read-only values and use scaling exclusively to change the width and height of an object.
I always use obj:scale().
thanks it’s work.
Why did it works better than changing widh and height ?
No idea since I can’t see the internals, but I’m going to assume that width and height are transient values that are re-updated each time the sprite source image changes, where as current scale factor is permanent until changed.
Actually this is the answer:
For images, the returned value is the original bitmap width, including any transparent area.
https://docs.coronalabs.com/api/type/DisplayObject/width.html#overview
Since you are effectively changing this on each frame change, the value is getting updated.
Note / Word of Advice:
I always treat width and height as read-only values and use scaling exclusively to change the width and height of an object.