Change the scale of a sprite

I have a question about the scale of sprites. We were playing around with making the sprites grow and shrink. I noticed that when you are decreasing the value of the scale property, once the value becomes a negative number, the sprite begins to get bigger.

So instead of adding and subtracting from the scale, I told my students to multiply and divide.
For example:
To grow the sprite - sprite.scale = sprite.scale * 1.05;
To shrink the sprite - sprite.scale = sprite.scale / 1.05;

That way, the scale never becomes a negative number and continues to shrink infinitely.

My question is, why does the sprite get larger once the number is negative? Does the code actually take the absolute value of the number? Just curious.

Kammie,

Calling in backup - will hopefully have an answer for you soon!

I sort of assumed it took the absolute value of the number. Its fun when students subtract from the value in the draw loop and then all sudden the sprite gets bigger. Its a great opportunity to talk about math with students who donâ€™t always enjoy math class.

Did we ever get a definitive answer on this?

Did we ever get a definitive answer on this?

1 Like

I donâ€™t know that I can say that my answer is definitive, but in my experience, it doesnâ€™t just get bigger, but it flips the sprite inside out. There are other ways around it such as using a conditional statement that tells the sprite to shrink until the scale is 0, but I have seen some unexpected results before and have had to help some of my students realize that they needed to make sure the value didnâ€™t get below zero or have a contingency plan in place if it did happen.

Mike

Yes, even i have seen that when we reduce the value of scale as in â€śsprite.scale = sprite.scale - 0.005â€ť or something like that, it doesnâ€™t reach 0 . Somewhere through the course of this repeated reduction it changes its value like below: Not sure whyâ€¦curious about this behaviour

• 0.3765

• 0.3715

• 0.3665

• 0.3615

• 0.3565

• 0.3515

• 0.3465

• 0.34149999999999997

• 0.33649999999999997

• 0.33149999999999996

• 0.32649999999999996

• 0.32149999999999995

• 0.31649999999999995

• 0.31149999999999994

• 0.30649999999999994

• 0.30149999999999993

• 0.29649999999999993

Yes. You have discovered that computers actually have a hard time doing math with decimals. Hereâ€™s an article with more information on that!

Mike

Thank you so much for the reply!
Read through the article you shared, very interesting!
Thanks again

1 Like

Isnâ€™t this happening because once the sprite reaches 0, it is then subtracting a negative number which cancels out into adding?

1 Like