[C++] ID3DXSprite can't transform with animations

Started by
4 comments, last by zyrolasting 14 years, 2 months ago
My sprites always share the position of the first sprite if I try to animate them. I call ID3DXSprite::SetTransform before every draw, and I have confirmed that the correct information is set for every sprite. There are 3 sprites on my app that all share the same texture, and therefore the same animation. I generate a RECT every frame (if necessary) to pass to the pSrcRect parameter of ID3DXSprite::Draw. It's pretty obvious how to do so with the above image. Take a RECT of the first frame and just shift the thing over, looping back if necessary. If I use a constant RECT of the first frame, all the sprites are placed exactly where I want them. However, if I use my animations, all sprites snap to the position of the first even though the correct transformations are passed. If you need to see relevant snippets... With animation
m_pSprite->SetTransform(&matrix);
// Everything animates fine... in one spot.
m_pSprite->Draw(m_pTexture,&m_SpriteSheet.Output,0,0,~0);
Without animation
RECT r = {0,0,64,64};
m_pSprite->SetTransform(&matrix);

// Everything is placed fine... With no animation
m_pSprite->Draw(m_pTexture,&r,0,0,~0);
So, everything is fine except the pSrcRect param is giving me a black and white situation. What gives?
Advertisement
Do you call sprite->Begin/End?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Of course. Begin() takes only D3DXSPRITE_ALPHABLEND.
It's not a problem I've seen before. Does it work correctly if you call Flush after calling Draw?
Nope... Here's the smallest bit of the most relevant code I have. I'm on an event-driven model.

m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);m_Entities.PropogateMessage( EntityStorage::Message( CMSG_RENDER ) );m_pSprite->End();


Everything is drawn in PropogateMessage(). You don't need to see that since it works. Just know it passes a message to each stored entity via a virtual method on them.

Render message handling:
case CMSG_RENDER:{	// Bail if there is no texture	if ( !m_pTexture ) return -1;        // Sprite object grabbed in another event.	m_pSprite->SetTransform(&TransformationMatrix);	m_pSprite->Draw(m_pTexture->GetTexPointer(),&m_SpriteSheet.m_Child,0,0,m_ARGBBlend);	// m_pSprite->Flush(); <- Tried with and without}


I don't want to overwhelm, so I won't post any more code unless I'm asked. I'm suspicious of the SpriteSheet object I use, but that would mean I assume the pSrcRect parameter actually moves the sprite. I doubt it's really busted.
I found the problem.

As mentioned, I had 3 objects that used the same sprite. They each query a texture from a database. If it fails, they load the texture and add it to the database.
All this is done in an if statement, and I erroneously put the code for setting up animations in that block, meaning only the first sprite was set up properly. Sprites 2 and 3 were passing crap RECTs to Draw().

This topic is closed to new replies.

Advertisement