Sign in to follow this  

My entities

This topic is 4597 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, I am tinkering with a game and have come across something I wish for advice on. I have a Sprite class that stores the location of the sprite on the bmp (the fram I guess you'd call it), the type of sprite (base layer, character layer, etc). I also have an Entity class which will be used for my characters. It stores in a Linked List the sprites used for an animation, as well as other things such as place on the map and textureID. Anyways, my question is: should I make the LinkedList an array, and basically have each type of animation another List in the array? Or should I create seperate Entity's for each animation? For example jumping, running, walking, swimming, etc. I think that an array of Lists would be alright, but things could be difficult to manage and keep track of which lists are at which index. Should I create an enumeration, and use this is my animation index controller? So my walking animation would look like.... player1->GetNextImage(WALKING); I'm sorry if this post is all over the place, I have many questions about storing animations and character info. I kinda made this method up myself, so any help is welcome!

Share this post


Link to post
Share on other sites
HI,

Well if you know the amount of data and if its quite small, then array is the best bet.

For animation - you could 1-4 idle, 5-8 walking, 9-12 running, 13-16 jumping,16-20 swimming etc. This way you know what animation to call when you are going to do a certain part. That way neither do you need a seperate entity for each animation nor would you really need a list for animation. All you need to do is store the texture and translate the texture coordinates accordingly if you are using a 3d api otherwise just need to translate the width and height of image accordingly if you are using direct draw.









Share this post


Link to post
Share on other sites
Im using openGL to handle the graphics. I think using an array would be fairly easy, because I could have an enumeration and use that to determine which index I should be using at the time. If a new button is pressed, change the current index the entity is currently using and my drawing function would always act the same. The entity will determine which index is being used, based on what I set it to earlier.

Does this make sense?? haha. Im full of ideas, the problem is Im not sure how everyone else does it.

Share this post


Link to post
Share on other sites
Almost everyone does it differently. If you have few states that enumeration and using an array seems fine. I did it that way and didn't run into any problems. Except maybe when the heights and widths were different for the sprite (i.e. laying down instead of standing up).

Make sure to plan it out thoroughly before coding it.

Share this post


Link to post
Share on other sites
There is no better way of finding out than trying. I would suggest an array in your case as link list just seems to complicate things as it looks like currently. And if all the animations have same set of animation and you plan to have an enum to do it, no point in complicating code.

Share this post


Link to post
Share on other sites
Arrays are generally faster than linked lists. Only when you frequently need to insert and remove from the middle of an array will a linked list perform better. This is because arrays cache much better.

Typically, most games keep all animations for an entity with that entity, so you'd probably have something like a map (or array) of animation name to array of frames.

Share this post


Link to post
Share on other sites

This topic is 4597 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this