7 Replies - 849 Views - Last Post: 12 May 2012 - 12:51 PM Rate Topic: -----

#1 Hseptic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 11-May 12

Page flip animation doesn't animate correctly

Posted 11 May 2012 - 06:23 PM

My explosion animation does not animate as intended. All the frames seem to be messed up. For example, the first 15 frames or so don't show up. Also, there is a large circle towards the bottom of the source image (png format) an area that is never supposed to be used, yet parts of this circle show up in the animation. I tried using an animation image that is known to work (an image from a book's website, same dimensions), and this image animates as expected. So why doesn't mine work?

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

Attached Image

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));
}




Is This A Good Question/Topic? 0
  • +

Replies To: Page flip animation doesn't animate correctly

#2 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Page flip animation doesn't animate correctly

Posted 11 May 2012 - 07:56 PM

At a guess this sounds like the offsets are off, but other than that I'm not too sure, sorry.
One thing that might be causing a problem though is this line:
++i->currentFrame;


Since I believe it is analogous to this:
(++it)->currentFrame;


Was This Post Helpful? 0
  • +
  • -

#3 Hseptic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 11-May 12

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 06:05 AM

How do I correct offsets?
Was This Post Helpful? 0
  • +
  • -

#4 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 06:56 AM

Have you fixed what I highlighted before? (It needs to be ++(it->currentFrame;
By the offsets being off I simply mean that the x and y coordinates on the sheet must be off if they are taking the wrong part of the png. However I am not well-versed in D3D so all I can say is check the initial value of currentFrame, and check anything that involves the x and y coordinates. For example, give them some arbitrary values to see if they are loading the right values at all.
So if you have
RECT myR = {0, 0, 64, 64};


instead of what you have, you can check if it loads the very first frame. If it does, then your problem was with the code you just replaced. Else the problem lies in a further on part of the code, where you can do similar things to see if the problem is there instead.
Was This Post Helpful? 0
  • +
  • -

#5 Hseptic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 11-May 12

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 07:10 AM

I figured it out. Apparently the animation is starting at the bottom corner of "explosion.png" and page flipping backward. That's why the circle showed up and the first few frames didn't! So now the question is how do I get it to start animating at the top corner of the png file like it's supposed to.
Was This Post Helpful? 0
  • +
  • -

#6 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 07:27 AM

So the y-value is off but the x-value is okay? If that's the case then might be you need to change how you are using the y-value. Try starting from the largest y-value and working down, instead of from the smallest up.
Was This Post Helpful? 0
  • +
  • -

#7 Hseptic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 11-May 12

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 08:25 AM

How do I do this exactly? Which is the y value, i_index or j_index? Sorry, I'm still new.
Was This Post Helpful? 0
  • +
  • -

#8 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Page flip animation doesn't animate correctly

Posted 12 May 2012 - 12:51 PM

It looks like i_index is your y-value, so try
RECT myR = {j_index * 64, 512 - i_index * 64, (j_index+1) * 64,  512 - (i_index+1) * 64};


And see what happens
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1