Sprite Width relative to screen width

This question might seem silly, but is there a way to set the width of a certain sprite relative to display.contentWidth.

Let’s say I want my sprite width do be equal to display.contentWidth / 3:

  • Setting the relative width in the sprite sheet wouldn’t work.
  • Setting the width parameter of the sprite works until the spite start animating. I end up with a cropped (or  smaller) image, not filling the desired width.

Can this be done in any way? If not can you suggest another way of animating an image with relative widths?

Thanks 

Hi @astazed,

Did you try scaling the object instead of setting its width?

http://docs.coronalabs.com/api/type/DisplayObject/scale.html

If you’re using physics, though, be aware of the “Gotcha” described on that page.

Best regards,

Brent

Hey thanks for your reply. Scaling did it for me in addition to setting the width parameter to make the physics work as intended. But I have to reapply the scale after each item.play().

Thanks for your help 

Hi @astazed,

Did you try scaling the object instead of setting its width?

http://docs.coronalabs.com/api/type/DisplayObject/scale.html

If you’re using physics, though, be aware of the “Gotcha” described on that page.

Best regards,

Brent

Hey thanks for your reply. Scaling did it for me in addition to setting the width parameter to make the physics work as intended. But I have to reapply the scale after each item.play().

Thanks for your help