Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Game object management

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

Hi, I need a little help with my game object management. I am trying to create lists of cObjects, in a std::vector list - pObjectList->add( pObject) ; I can then say: pObjectList->render(); and my app will render all the items in the list. Unfortunately, I have become muddled due to my pointers I think. Heres my pseudo code: Cobject* pTempObject = new Cobject( device ); pTempObject->create( meshfilename, position, OBJECT_TYPE_LAND ); pObjectList->add( pTempObject, "Tank" ); pTempObject->create( 2ndMesh, position, OBJECT_TYPE_AIR ); pObjectList->add( pTempObject, "PLANE" ); I get two poiunters to objects in the vectorlist, but they are both pointers to the same thing (the address of the pTempObject, I imagine!). How can I do this correctly? Ideally I am creating an object, copying it into the list, creating another, and copying that one too without affecting the first. Should I not use pointers to Cobjects? Any help, much obliged! Thanks Simon

Share this post


Link to post
Share on other sites
Advertisement
You are only creating 1 object Cobject* pTempObject = new Cobject( device );

But you are calling create on the same object twice. The pointer never changes. It sounds like you want to create 2 different objects, so you need to new another Cobject for your 2nd call to create.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
try this:

Cobject* pTempObject = new Cobject( device );
pTempObject->create( meshfilename, position, OBJECT_TYPE_LAND );
pObjectList->add( pTempObject, "Tank" );

Cobject* pTempObject = new Cobject( device );
pTempObject->create( 2ndMesh, position, OBJECT_TYPE_AIR );
pObjectList->add( pTempObject, "PLANE" );

but remember to delete all pointers in your list before destroying list itself

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ups redefinition :p
4th line should be:
pTempObject = new Cobject( device );

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!