# Sprites...

## Recommended Posts

Ive decided to make a 2d tile game but before i started i thought i should learn to draw tiles. The below function will draw a tile but i belive that there is a way to rotate a tile and or scale it.
//m_Texture is a IDirect3DTexture9*
//m_Graphics holds the Direct3D things
Blit(long DestX, long DestY,long SrcX, long SrcY,long Width, long Height,float XScale, float YScale,D3DCOLOR Color)
{
RECT Rect;
ID3DXSprite *pSprite;

if(m_Texture == NULL)
return FALSE;
if(m_Graphics == NULL)
return FALSE;
if((pSprite = m_Graphics->GetSpriteCOM()) == NULL)
return FALSE;

if(!Width)
Width = m_Width;
if(!Height)
Height = m_Height;

Rect.left = SrcX;
Rect.top  = SrcY;
Rect.right = Rect.left + Width;
Rect.bottom = Rect.top + Height;

if(FAILED(pSprite->Draw(m_Texture,&Rect, &D3DXVECTOR3(XScale, YScale,0.0f),&D3DXVECTOR3((float)DestX, (float)DestY,0.0f),Color)))
return FALSE;
return TRUE;
}


This function is supposed to draw a tile scaled to XScale and YScale butit doesnt. It will draw a tile in the right place but it wont scale or rotate it at all. I did manage to scale the tile by creating a matrix and using pSprite->SetTransform(&MatScale), but it doesnt look right and when i try to rotate anything the tiles will do some crazy stuff. So my question is how do i rotate or scale tiles? and am i even drawing them right?

##### Share on other sites
Im i not explaining this well

##### Share on other sites
According to the timestamps, this thread has only been open for 20 minutes. It might not be forum rules, but "bumping" a thread in less than 24hrs is generally frowned upon [wink]

Give people more time - we'll often reply asking for more details if/when we need them.

Cheers,
Jack

##### Share on other sites
Hey.. try this it should work...

Blit(long DestX, long DestY,long SrcX, long SrcY,long Width, long Height,float XScale, float YScale, float rotation, D3DCOLOR Color){  RECT Rect;  ID3DXSprite *pSprite;  if(m_Texture == NULL)    return FALSE;  if(m_Graphics == NULL)    return FALSE;  if((pSprite = m_Graphics->GetSpriteCOM()) == NULL)    return FALSE;      if(!Width)    Width = m_Width;  if(!Height)    Height = m_Height;  Rect.left = SrcX;  Rect.top  = SrcY;  Rect.right = Rect.left + Width;  Rect.bottom = Rect.top + Height;    D3DXVECTOR2 scaling(XScale, YScale);	  D3DXMATRIX  mat;  D3DXMatrixTransformation2D( &mat, NULL, 0.0f, &scaling, NULL, rotation, NULL );  m_sprite->SetTransform(&mat);  if(FAILED(pSprite->Draw(m_Texture, &Rect ,NULL ,&D3DXVECTOR3((float)DestX, (float)DestY,0.0f),Color)))    return FALSE;  return TRUE;

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628350
• Total Posts
2982217

• 10
• 9
• 24
• 11
• 9