Sprite sizes

Started by
4 comments, last by Eralp 15 years, 11 months ago
Hi, this question could also go to "for beginners" section but whatever.. I am creating my guisystem(so far I have started good ^^) and I wrote my draw functions etc. about my "buttons".Then I wanted to make them sizable(coded sizes, not in runtime),however I realiazed that I have nowhere to put a RECT variable that holds screen coords which the sprite will be stretched to.I know how to scale but as far as I know I can only scale by the multiple of 2.(though its logical when I think) So what can I do to get my sprite drawn stretched exactly where I want it to :S and you know I don't want all my buttons to be in the same size or by 2 multiplied size :).
Advertisement
You can scale by whatever you want when you're rendering, quads can have any arbitrary size and position. How exactly are you rendering your sprites?
I am drawing my sprites like this;

void Button::Draw(LPD3DXSPRITE &d3dspt,LPD3DXFONT &dxfont){D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);    D3DXVECTOR3 position(X, Y, 0.0f);   d3dspt->Draw(sprite, NULL, &center,&position, D3DCOLOR_ARGB(200, 255, 255, 255));}


my loading function is ;

void LoadTexture(LPDIRECT3DTEXTURE9* texture, LPCTSTR filename){    D3DXCreateTextureFromFileEx(d3ddev, filename, D3DX_DEFAULT, D3DX_DEFAULT,    D3DX_DEFAULT, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,     D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), NULL, NULL, texture);    return;}
You can use ID3DXSprite::SetTransform to set a transformation matrix to draw with. This will affect the size of the sprite, as well as the position. If you pass a scaling matrix, you can scale a sprite to an arbitrary size.

Keep in mind, however, that the position is scaled as well, so you'll have to scale the position by the inverse amount before drawing, so that after it gets scaled it is exactly where you intended it to be.
Sirob Yes.» - status: Work-O-Rama.
What you might want to do is instead of specifying a position in ID3DXSprite::Draw is to use D3DXMatrixTransformation2D to create a single transform matrix for your positioning and scaling.
Yayy I got it now, I'm familiar with matrixes since I was doing 3 d programming before but I thought you could only scale it by multiple of 2 when you use SPRITES.sorry for taking your time, but thanks though :)

This topic is closed to new replies.

Advertisement