Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zygo_#2000

Holding sprites

This topic is 6545 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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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 lists
while(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

Share this post


Link to post
Share on other sites
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[i]->Draw()
}


this adds MAX_SPRITES if''s each time you wanna draw everything - again consider the situation of using a small fraction of your array...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!