Deleting a game object

Posted by Balls on Game Development See other posts from Game Development or by Balls
Published on 2012-10-06T16:31:41Z Indexed on 2012/10/07 3:53 UTC
Read the original article Hit count: 160

Filed under:
|
|

I tried doing this but it cause an access violation.

void GameObjectFactory::Update()
{
     for( std::list<GameObject*>::iterator it=gameObjectList.begin() .....
          (*it)->Update();
}

void Bomb::Update()
{
     if( time == 2.0f )
     {
         gameObjectFactory->Remove( this );
     }
}

void GameObjectFactory::Remove( ... )
{
     gameObjectList.remove( ... );
}

My thoughts would be to mark the object to be dead then let the factory handle it the on next frame for deletion. Is it the best and fastest way? What do you think?

© Game Development or respective owner

Related posts about c++

Related posts about data