# DirectX9 Drawing Sprites out of place due to offset

This is my very first time into DirectX. Im trying to make a simple 2D game, just for learning the basics. And i've achieved that. The next step is to draw an animation using sprites.

Ok, now, the problem im having is that, the metadata that i get from spritebuddy (and i know is not the spritebuddy data that is wrong because i downloaded a few more software and the result was the same) come with a offset for every sprite.

Now, when im drawing, i said, lets add the offset to the position of the sprite, that should do it. Annnnnd it didnt, so i started to manualy change the metadata to see how bad was it. The result was that on the y axis, if you doubled the ammount in the metadata, the drawing was a lot less messy.

Is there something im doing wrong?

SpriteData* metadata = this->m_pXMLTraductor->getSpriteDimension(numFrame);//the number of the frame we want the dimensions
D3DXVECTOR3 vCenter(0.0f, 0.0f, 0.0f);

this->m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
this->m_pSprite->Draw(
this->m_pTexture->GetTexture(),
&temp,
&vCenter,
&vPosition,
D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, 1.0f));
this->m_pSprite->End();
long long cont = 0;
this->numFrame++;
this->numFrame = 0;
}


This is how i render the model.

Is there any other way to do this? Srry about my english. Im working on it too ^^

• I'm not sure why you decided to start with Direct3D 9, but DirectX Tool Kit for Direct3D 11 has a very easy to use SpriteBatch class and docs on using sprite sheets with it. – Chuck Walbourn Apr 15 '15 at 7:09

I personally haven't used the method your using. But since you have asked if there is another way to do this...

Suppose you have a texture atlas (texture made up of sub-textures) where each sub-texture has the same dimensions:

Then if you create a RECT R = {j*64, i*64, (j+1)*64, (i+1)*64};

->Where int j = currentFrame / 6 //row

->Where int i = currentFrame % 6 //col

->(6 because of 6 sub-textures in a row)

->Where 64 is the width and height of the sub-texture

You would simply use this line to draw:

mSprite->Draw(yourTexture, &R, &mSpriteCenter, 0, D3DCOLOR_XRGB(255, 255, 255));


So as you update your currentFrame in an update method, this will effectively update your rect to be draw from the texture.

Additional note: I learned this method from Introduction to 3D Game Programming With DirectX 9.0c A Shader Approach - by Frank D. Luna