I'm attaching my image file, "explosion.png", for reference. Sorry about the "explosion", I drew it myself.

Here are the two methods that deal with the explosion page flipping...
void AsteroidsDemo::updateExplosions(float dt)
{
std::list<ExplosionInfo>::iterator i = mExplosionList.begin();
while( i != mExplosionList.end() )
{
i->timeAccumulated += dt;
if(i->timeAccumulated >= 1.0f / 30.0f)
{
++i->currentFrame;
i->timeAccumulated = 0.0f;
if(i->currentFrame > 29)
{
if(i->type == SHIP)
gameover = true;
i = mExplosionList.erase(i);
continue;
}
}
++i;
}
}
#define COLS 6
void AsteroidsDemo::drawExplosions()
{
// Turn on the alpha test.
HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true));
std::list<ExplosionInfo>::iterator i = mExplosionList.begin();
while( i != mExplosionList.end() )
{
int i_index = i->currentFrame / COLS;
int j_index = i->currentFrame % COLS;
RECT myR = {j_index * 64, i_index * 64, (j_index+1) * 64, (i_index+1) * 64};
D3DXMATRIX T;
D3DXMATRIX I;
D3DXMatrixIdentity(&I);
D3DXMatrixTranslation(&T, i->pos.x - mShipPos.x, i->pos.y - mShipPos.y, i->pos.z - mShipPos.z);
HR(mSprite->SetTransform(&(I*T)));
HR(mSprite->Draw(mExplosionAnim, &myR, &mExplosionCenter, 0, D3DCOLOR_XRGB(255, 255, 255)));
++i;
}
HR(mSprite->Flush());
HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false));
}

New Topic/Question
Reply



MultiQuote



|