Jump to content
  • Advertisement
Sign in to follow this  
treetrunker

Lists, Queues, and Animation

This topic is 2549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody.
Currently I'm working on a portion of a project that involves sprite style animation using SDL and C++. I've been attempting to implement the animation of these sprites in a queue-type list that I've set up. This queue loads in the images for the animation and then loops through said images until an event changes the animation in the list.

The problem I'm having is that I'm not sure how to set it up so that the maximum length of the list is dynamic. I know i can declare the max length at run time using pointers, but this seems like it would become tedious when each character within the game will have animations of differing frame lengths. I did some reading on linked lists, and this seems to be the way to go, but the book I've been using uses VERY clunky notation that seems like it removes the purpose of array type programming in the first place.

They do things like this:

head->link->link->info

Now, I feel like the linked list style is what I need, but is there a better way of implementing it? I'm looking for a method that allows me to access components of the list simply using an index, while maintaining the dynamic nature of the linked list, since the maximum size of my list will be highly variable.

Thanks in advance! :D

Treetrunker

Share this post


Link to post
Share on other sites
Advertisement
If you're using C++ then you've got access to a number of different containers include std::vector and std::deque, both of which are dynamic sequence containers that allow indexed element access.

Share this post


Link to post
Share on other sites
For some reason I was under the impression that I would have to declare a max size with those containers. On closer inspection the vector class works perfectly. Thanks! :D

Share this post


Link to post
Share on other sites

For some reason I was under the impression that I would have to declare a max size with those containers. On closer inspection the vector class works perfectly. Thanks! :D


Why would it matter that you give it a "max size"? The size of a vector is the amount of items you put into it. So, if you're animation has 5 frames, you push the 5 frames into the vector, then loop over vector.size(). If it has 14 frames of animation, put the 14 frames in the vector, and loop over vector.size().

Shouldn't matter.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!