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.

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.

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.

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