0
\$\begingroup\$

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.

For that, i downloaded SpriteBuddy, a very simple and user friendly software that helps you creating the metadata for your spritesheet.

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
RECT temp = metadata->position;
D3DXVECTOR3 vCenter(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vPosition(this->vPosition.x + this->metadata->offset.x, this->vPosition.y + (metadata->offset.y*2) , 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++;
if (this->numFrame > this->m_pXMLTraductor->spriteCounter()){
    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 ^^

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 15, 2015 at 7:09

1 Answer 1

1
\$\begingroup\$

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

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .