Setting the Height of a Sprite Reveals the full texture, the mask scales but not the underlying image

I was experimenting last night and one experiment involved changing the height of a sprite. This did not have the desired outcome and instead of the sprite being scaled vertically the mask was scaled and the underlying image was not.

I this going to be default behaviour? [import]uid: 5354 topic_id: 1725 reply_id: 301725[/import]

Sounds like a bug, but I’m looking at scaled (and rotated) sprites right this second and it looks fine. What’s the code? [import]uid: 54 topic_id: 1725 reply_id: 5074[/import]

Hi Eric

Not got the code to hand but I can describe what I did

Load a new sprite sheet 320 x 480 and divide into sprites 320 wide 1px height

generate a new 1px high sprite from this.

set the .height to say 50

for me the sprite was not stretched vertically but rather 50px of the original image were shown rather than the 1px stretched to 50px

Matt [import]uid: 5354 topic_id: 1725 reply_id: 5090[/import]

We’ll try to repro. Case #734. [import]uid: 54 topic_id: 1725 reply_id: 5096[/import]

This is now fixed. Setting width/height won’t affect the sprite’s width/height, use xScale/yScale instead. [import]uid: 54 topic_id: 1725 reply_id: 6490[/import]

Not really a fix, might need to set the height in pixels at some point. [import]uid: 5354 topic_id: 1725 reply_id: 6491[/import]

Hm, ok, I’ll look at this again. [import]uid: 54 topic_id: 1725 reply_id: 6494[/import]

Setting the width/height of an image doesn’t scale the image. So I don’t think it should scale the sprite either.

Why wouldn’t using xScale/yScale to scale the sprite be satisfactory? [import]uid: 54 topic_id: 1725 reply_id: 6548[/import]

Well I might want to set an object to a specific height, for whatever reason. I just might want to say be 50px high rather than be 25% high to get the same effect

If the layout is in pixels then it just seems natural [import]uid: 5354 topic_id: 1725 reply_id: 6550[/import]

You can set the height to 50 pixels using for example
sprite.yScale = 50 / sprite.height
I can see there might be a slight issue with exact math, and rounding, and it is a little bit less straightforward.

One issue that occurs to me is, what do we do if the sprite changes its height? You might ask, how can that happen, but that would be telling :slight_smile:
[import]uid: 54 topic_id: 1725 reply_id: 6551[/import]