nazdar, tu knihu som mal tiez v ruke a v tom engine je chyba. Uz si to uplne presne nepametam, pretoze to bolo rok dozadu, ale upravoval som tieto dve metody:
void GameEngine::UpdateSprites()
{
// Update the sprites in the sprite vector
RECT rcOldSpritePos;
SPRITEACTION saSpriteAction;
vector<Sprite*>::iterator siSprite = m_vSprites.begin();
while (siSprite != m_vSprites.end())
{
// Save the old sprite position in case we need to restore it
rcOldSpritePos = (*siSprite)->GetPosition();
// Update the sprite
saSpriteAction = (*siSprite)->Update();
// Handle the SA_KILL sprite action
if (saSpriteAction & SA_KILL)
{
// Notify the game that the sprite is dying
SpriteDying(*siSprite);
// Kill the sprite
delete (*siSprite);
siSprite = m_vSprites.erase(siSprite);
continue;
}
// See if the sprite collided with any others
if (CheckSpriteCollision(*siSprite))
// Restore the old sprite position
(*siSprite)->SetPosition(rcOldSpritePos);
++siSprite;
}
}
a
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.clear();
}
Bol tam problem s nekorektnym odstranovanim prvkou vektora. Kniha je inak dobra, takze kludne pokracuj v citani. Este jednu taku malickost obsahuje ten engine, a to ze zatazuje cpu na 100%. Matne si spominam, ze som to riesil pouzitim casovaca. Pripajam preto kod z 19 kapitoly, hra meteordefense, ak chces tak sa nato mrkni.