if ((*siSprite)->GetYPosition() == y)//if it''s on that line
{
delete (*siSprite);//delete it
_pGame->GetSpriteVector().erase(siSprite);//get it outta vector
siSprite--;//move the movement backwards to account
}
But, i get an access violation if i don''t do it in a gameengine function and i don''t exactgly know about passing in iterators and how that would work. Help por favor
-----------------------------------------------------------
Like a sponge!
Passing Iterators into Functions
Alrighty, writing tetris game. When i want to delete a whole line, it''s done in the Tetris.cpp file, but the sprite and gameengine are their own classes and the sprite vector is in the gameengine. So, i write a gameengine function to erase a certain sprite. Now, i want to pass in the ITERATOR to the sprite, delete that sprite from memory and then erase it from the vector.
Actually, i think the scope prob could be in the "GetYPosition()" of the sprite... Here''s the whole function.
-----------------------------------------------------------
Like a sponge!
void DeleteLine(int y){ vector<Sprite*>::iterator siSprite; for (siSprite = _pGame->GetSpriteVector().begin(); siSprite != _pGame->GetSpriteVector().end(); siSprite++) { if ((*siSprite)->GetYPosition() == y)//if it''s on that line { delete (*siSprite);//delete it _pGame->GetSpriteVector().erase(siSprite);//get it outta vector siSprite--;//move the movement backwards to account } }
-----------------------------------------------------------
Like a sponge!
Alright, made it into a gameengine function, but i still get an access error on the GetYPosition()???
^^Unhandled exception at 0x00425cc5 in Tetris.exe: 0xC0000005: Access violation reading location 0x00a64000.
[edited by - draco5869 on July 7, 2003 12:24:46 AM]
^^Unhandled exception at 0x00425cc5 in Tetris.exe: 0xC0000005: Access violation reading location 0x00a64000.
[edited by - draco5869 on July 7, 2003 12:24:46 AM]
But somehow the function from the book works that''s basically the same thing:: okay, i''ll let someone else post now =)
void GameEngine::CleanupSprites(){ // Delete and remove the sprites in the sprite vector vector<Sprite*>::iterator siSprite; for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++) { delete (*siSprite); m_vSprites.erase(siSprite); siSprite--; }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement