scaling sprites

Started by
1 comment, last by localrob2 18 years, 7 months ago
Using directX9.0 and ID3DXSprite How can I scale sprites? Make them larger or smaller, without changing the actual bitmap file. this is the draw function HRESULT Draw( LPDIRECT3DTEXTURE9 pTexture, CONST RECT *pSrcRect, CONST D3DXVECTOR3 *pCenter, CONST D3DXVECTOR3 *pPosition, D3DCOLOR Color ); The old draw function had a scaling vector. Anyone have any suggestions?
Advertisement
You can use the SetTransform() function to set a scaling transform. Something like this (untested):
D3DXMATRIX matView, matProj, matScale, matFinal;pDevice->GetTransform(D3DTS_VIEW,&matView);pDevice->GetTransform(D3DTS_PROJECTION,&matProj);D3DXMatrixScaling(&matScale,2.0f,0.5f,1.0f);matFinal = matScale*matView*matProj;pSprite->SetTransform(&matFinal);pSprite->Draw(...);
That should scale by 2.0 in X and 0.5 in Y. Z isn't used, so you'll usually want to set it to 1.0.
And you need the view and projection matrices, because SetTransform() wants a matrix to translate from world space to screen space, not from model space to world space (which you'd just set matScale for).
thanks, I'll try that

This topic is closed to new replies.

Advertisement