So, how do I actually make this work?
Well, I go through and I take the time and I do some modular arithmetic, modulo 64 so
my number that I'm coming back with is always in the range from zero to 64.
And I do one thing a little kind of tricky here because this number is a fractional
number I don't want to have to actually index by a fraction,
I want to index by a whole number.
So I'm going to do integer division by one and
that takes the whole whole part of the number.
So, this gives me the index inside the tile image, and
now I do my computation of where the center should be.
It's the same thing before, we start at the center of the first sub image.
We add in the index times,
well this is the size of the rock in the horizontal direction.
And notice that the position of the vertical direction stays unchanged.
So when we're done we've actually got the current rock center.
We've got the rock center for the where we want to draw it on screen.
We might as well not draw it at the same place so that it appears it's moving.
So we're kind of ready to go here, so let's just do one thing,
let's go through and actually change the value of time.
So what I'm going to do next is I'm going to change this to where time is 1.
So every time we draw we stride through this animated asteroid image.
So I'm going to go through and make time equal one, and so
let's see what happens and wow!
Our asteroid is tumbling very very fast probably not a very realistic animation.
So this particular tile image has the property that if we kind of draw it at
kind of one draw per frame it's going to animate much too fast.
So we could go back and ask the artist to make us more frames in between so
we get a longer tiled image, or we can basically have it much shorter animation.
Or we could go through and
kind of slow it down by kind of adjusting this time variable.
So what can I do here is like I can maybe change this to 0.2.
So if we go through and
do that what you can see now is it's actually tumbling a little slower.
So at 0.2 every five frames time goes up by one so
every frame we're kind of flipping forward to the next image.
So this is really, if we do five frames,
takes five ticks to do a single frame and there's 60 ticks in a second,
we're kind of doing 12 frames a second in our animation.
And that's actually slow enough,
your eye can actually perceive this kind of jumpiness in there.
If we sped this up a little bit, maybe take it to 0.1,
let me actually 0.4 I think it'll start to look continuous.
Yeah it's going to start looking continuous here but
the problem is our asteroid is tumbling way too fast.
So fundamentally if we're going to try to animate this tumbling asteroid,
we don't have enough enough art here.
We need more frames in our animation to get a really good
realistic looking animation of a tumbling asteroid.
Okay let's look at another example.