1 decade ago by Zetaphor
Hello everyone, I'm trying to develop a formula for scaling the sprite of an entity to a maximum over a time. I'm constrained within the float range of 0.0-1.0 as I'm using the canvas context to perform the scale.
That's not really clear, allow me to explain the situation.
I have "baby creatures", when they're born they start at a predefined baby_size and grow to adult_size over time, time being current_age <= adult_age. I'm performing this check on a timer, current_age is incremented on every timer execution.
I have to use the canvas scale function to properly size my sprites, which accepts a float multiplier. 0.1 would should represent the baby_size and 1.0 the adult_size.
I also have to set the x and y size on the entity so collisions are mapped to the sprite dimensions. The sprites are always squares, so x = y
What I'm trying to get here is a formula that will give me, based on the current_age relative to adult_age, the 0.1-1.0 scale and the x,y scale based on adult_size relative to baby_size.
I'm also tracking current_scale across updates, as I set this in the timer to be used by the draw function.
Any help here is greatly appreciated, I'm terrible with math so my current attempts have failed :-(
That's not really clear, allow me to explain the situation.
I have "baby creatures", when they're born they start at a predefined baby_size and grow to adult_size over time, time being current_age <= adult_age. I'm performing this check on a timer, current_age is incremented on every timer execution.
I have to use the canvas scale function to properly size my sprites, which accepts a float multiplier. 0.1 would should represent the baby_size and 1.0 the adult_size.
I also have to set the x and y size on the entity so collisions are mapped to the sprite dimensions. The sprites are always squares, so x = y
What I'm trying to get here is a formula that will give me, based on the current_age relative to adult_age, the 0.1-1.0 scale and the x,y scale based on adult_size relative to baby_size.
I'm also tracking current_scale across updates, as I set this in the timer to be used by the draw function.
Any help here is greatly appreciated, I'm terrible with math so my current attempts have failed :-(