D3DXSprite - Draw() Paramters

Started by
3 comments, last by utilae 18 years, 5 months ago
Hi, I am using C++ and D3D9. I have some questions about the parameters for D3DXSprite Draw(). Here is the function from: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/ID3DXSprite__Draw.asp
Quote: HRESULT Draw( LPDIRECT3DTEXTURE9 pTexture, CONST RECT * pSrcRect, CONST D3DXVECTOR3 * pCenter, CONST D3DXVECTOR3 * pPosition, D3DCOLOR Color ); Parameters pSrcRect-Pointer to a RECT structure that indicates the portion of the source texture to use for the sprite. If this parameter is NULL, then the entire source image is used for the sprite. pCenter-Pointer to a D3DXVECTOR3 vector that identifies the center of the sprite. If this argument is NULL, the point (0,0,0) is used, which is the upper-left corner. pPosition-Pointer to a D3DXVECTOR3 vector that identifies the position of the sprite. If this argument is NULL, the point (0,0,0) is used, which is the upper-left corner. Color
1) About pSrcRect. If my texture, a .tga file is 64x64 and it is divided into four subtextures, then will the rect[top=1,left=1,right=32,bottom=32] be the top left subtexture? 2) About pCenter. Let's say that I want my sprite to be positioned at rect[top=100,left=100,right=200,bottom=200] on the screen, then what should pCenter be? (0,0,0) or NULL ok (I don't care about rotation, etc) ? 3) About pPosition. Let's say that I want my sprite to be positioned at rect[top=100,left=100,right=200,bottom=200] on the screen, then what should pPosition be? Note: that the z value can be anything. Anyone able to help?

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Advertisement
1) yes. but imo it starts form 0, so rect[top=0,left=0,right=32,bottom=32]

2) when placing a sprite:
upper left corner will be: pPosition - pCenter

in case of pCenter == NULL, or vector3(0,0,0), pPosition will be the upper left corner of the sprite naturally.

if you want to have your sprite centered at pPosition, pCenter mustbe vector3(sprite_width/2, sprite_height/2, 0)

3) as said before
if does not need to be centered:
pPosition(100,100,0), pCenter(NULL)

if centered:
pPosition(100,100,0), pCenter(sprite_width/2, sprite_height/2, 0)


afaik, z param does matter if you are sorting the sprites with the flag. if they dont overlap of no alphablend, it doesnt matter
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Ok, I understand now. The size of the sprite is determined by texture size.

But is there a way to make the sprite a different size to the texture size, eg twice or half as big?

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

I guess you can set a scaleing transformation for the sprite object. Ude D3DX to create a screenspace transform then set it with ID3DXSprite::SetTransform()
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Ok, could someone give me a bit of code.


I want to know what the matrix code is and how to use it to enlarge/reduce the sprite.

from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/transforms.asp
Quote:
The following example shows how to initialize a D3DMATRIX structure to act as a uniform scaling matrix.
// In this example, s is a variable of type float.
D3DMATRIX scale = {
s, 0.0f, 0.0f, 0.0f,
0.0f, s, 0.0f, 0.0f,
0.0f, 0.0f, s, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};

So would the above quoted matrix work.


So, to resize a sprite would the code below be right?
//assume following code between sprite begin/end functionsD3DXVECTOR3 *pPospos->x=100;pos->y=100;pos->z=0;float s=0.5;//50% of texture sizeD3DMATRIX scale={    s,               0.0f,            0.0f,            0.0f,    0.0f,            s,               0.0f,            0.0f,    0.0f,            0.0f,            s,               0.0f,    0.0f,            0.0f,            0.0f,            1.0f};g_pSprite->SetTransform(scale);g_pSprite->Draw(TextureManager.GetTexture("Texture1.tga"),    TextureManager.GetTileRect("Texture1.tga","Tile1"),    NULL,    pPos,    D3DCOLOR_XRGB(255,255,0));

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

This topic is closed to new replies.

Advertisement