Jump to content


Multiple objects


3 replies to this topic

#1 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 20 March 2006 - 11:54 PM

I want to have a generic "Object" class, that has Item and Entity as it's children. those children have children... and etc.

Basically I want to declare the children and use them without taking up much memory, however, if I have 100 entities (99 enemies and 1 player), how would I make it so that they each could be an instance of a class without having to load the bitmap and source of the bitmap into their blitting function every time?

Simplified: What I'm trying to do is be able to have classes of Items(weapons, armor) and Entities(Playerse, Enemies, bosses) and use them effectively.

So what's the best way of doing this, dealing with general design? I want to be able to use many of them.


So I guess just basic entity design.

Thanks,

Jason

#2 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 21 March 2006 - 01:29 AM

What I'm thinking of doing is having a file:

Item.h/cpp

And having classes within that file:

Weapon
Armor
Obstruction //tables and shit


Then, in the map class (which handles everything), I'd have a bitmap for each item generically, and then have the classes only hold their position and status. Then, dynamically, I could have a draw() function that loops through the vector/whatever of objects and draws them based on the passed in bitmap?

I really have no idea

Thanks,

Jason

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 21 March 2006 - 01:56 AM

How about letting each entity hold a pointer to its bitmap, or a handle of some kind (the bitmap is managed by a resource manager, or the top-level map object)? Then you could sort them by bitmap and draw all that have the same bitmap at once.
reedbeta.com - developer blog, OpenGL demos, and other projects

#4 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 21 March 2006 - 02:06 AM

Good idea, thank you. I guess what I normally do is store the usable graphics pointer in the class, so I wouldn't have extra parameters floating around each frame. But, I guess in this case, the extra overhead is needed so I don't have to store bitmaps in each designated class.

Thank you,

Jason





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users