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

This topic is 3046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Share on other sites
Do you call sprite->Begin/End?

Share on other sites
Of course. Begin() takes only D3DXSPRITE_ALPHABLEND.

Share on other sites
It's not a problem I've seen before. Does it work correctly if you call Flush after calling Draw?

Share on other sites
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.

Share on other sites
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().

• 11
• 20
• 12
• 10
• 34
• Forum Statistics

• Total Topics
631399
• Total Posts
2999854
×