About "Basic animation in LWJGL"

Hello.

I wasn’t sure whether to create a new topic for this - I know it’s nice to have separate topics for different things despite them being related - but I’m asking a question based of someone’s response to another question.

In AppleSauce’s thread, he asked about how to do basic 2D animation in LWJGL. Now, in the past, I’ve always done this by having 1 texture (A strip) and timing how much time has gone past inbetween each frame. when this reaches the right amount, I change the ‘viewing window’ or the texture coordinates to the next frame - and I assumed this was standard.

But Drenius put this:

[quote]If you think you are fine, ok.
Having a timer for every single texture in the program is a waste.
Make it jump to the frame it has to be in when it is rendered when it is rendered.
[/quote]
Maybe I’m misunderstanding what was said, but from what I understand the method I’m using is a waste as I use multiple timers for each animation.

I don’t understand what I should do instead - “Make it jump to the frame it has to be in when it is rendered” ??

Sorry, I’m at a loss, can anyone help?:stuck_out_tongue:

Can you show us how you render your sprites?

This really should be in the same thread, as it is simply a reply to a comment…

I believe he means something like this:


render() {
    drawImage(animation.getFrameForTime(currentTime));
}

Where getFrameForTime() takes frame duration and looping information into account to spit out what frame the animation is currently on, no timer required.

I placed the second “when it is rendered” for a reason, also the second “when” was itallic for a reason.
If you do not render a texture within a time span, you must not update it.
You should just save when the last frame change took place and once you render the texture again, you can check how many frames must have passed since then and set it to that frame.

But the location that the sprite needs to be could change every frame, isn’t it less complex to just render it each frame? Especially with a moving camera - or should I be keeping track or if I need to redraw it?