Holding sprites

Started by
4 comments, last by Zygo_#2000 23 years, 10 months ago
What is a normal way to hold sprites. I need to hold information such as x and y position and velocity and some more informations. I could keep them in a linked list, would this be a good idea??? How do games like Warcraft and so do it??? Thanks in advance
Advertisement
Hmm... I would probably build a struct or class...

ie:

struct SPRITE{
long x;
long y;
long xv;
long yv;
BITMAP Bitmap;
....
....
....
};

Enoch Dagor
Enoch DagorLead DeveloperDark Sky EntertainmentBeyond Protocol
quote:Original post by Zygo_#2000

I could keep them in a linked list, would this be a good idea??? How do games like Warcraft and so do it???


A linked list is a possibility, but makes things more complex than needed if you ask me. Maybe it''s better to concentrate on more complex things that cannot be done simpler...

I always use simple arrays with a maximum number of sprites.
It also may be a good idea to split the information into more structs. (ever done database design?)

Just an idea:

    typedef enum{  SPRITE_PLAYER,  SPRITE_EXPLOSION,  SPRITE_KNIGHT,  SPRITE_ZOMBIE,  ...}ESPRITE;typedef struct{  int   iWidth;  int   iHeight;  char  *pPicture;  float iCollisionWidth;  float iCollisionHeight;  ...}SPRITE, *PSPRITE;typedef struct{  float   fXPos;  float   fYPos;  float   fVelocity;  float   fAngle;  ESPRITE eSprite;  ...}OBJECT, *POBJECT;SPRITE Sprites[] = { ... };OBJECT Objects[MAX_OBJECTS];int iObjects = 0;    


Now you can use the Object[x].eSprite as an index for the Sprites array.

I can keep talking for hours...
If you want me to go on, just say so...
Want a uge tutorial on this...?...hmmm....

Thanks to both of you...
To baskuenen: Yes, just keep talking, and if you got a huge tutorial on this, then send it to me (Zygo_x2000@inbox.as).
Thank you...
I would use the simple arrays.......in the old days (maybe like 2-3 years ago).....maybe linked lists because of the whole memory vs speed issue (you had to give up some of one to get more of the other).......but now things are geared mostly for speed because the memory isn''t as much of a problem as it used to be......
and simple arrays are much faster then linked lists......
say you had 100 elements.......and wanted the last one.....
to access with arrays
    whatever = myArray[99]or this for linked listswhile(listItem->nextNode != NULL){   listItem = listItem->nextNode;}whatever = listItem->myInfo;    


you tell me which is faster......


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

DO NOT USE AN ARRAY!
use a STL vector (or list) that way you are not limited to a certain number of sprites.

it''s no harder to implement, is hardley any slower (if at all) and is just better.

quote:A linked list is a possibility, but makes things more complex than needed if you ask me. Maybe it''s better to concentrate on more complex things that cannot be done simpler...


no. it is only more complex if you implement your own linked list (which is pretty much a pointless waste of time since STL''s will probably be faster, more stable, better tested etc...)

also - you must make sure there is a sprite in each array index before drawing it:

for(int i=0; i{if(arraySprites != NULL) arraySprites->Draw()<br>}<br> </pre> <br><br>this adds MAX_SPRITES if''s each time you wanna draw everything - again consider the situation of using a small fraction of your array…  </i>   

This topic is closed to new replies.

Advertisement