Hello, mates.
first question is, how to draw text over the sprite? I'm trying to draw text on my sprites, but it seems the texture is being drawn over the text, how can i make the text be over the texture? here's my render code:
Sprite->Begin ( D3DXSPRITE_ALPHABLEND );
if ( bText )
{
RECT rc;
rc.left = text.x;
rc.top = text.y;
TEXTMETRICA met;
text.font->GetTextMetricsA ( &met );
rc.right = rc.left+(strlen(text.Text)*met.tmHeight) + 10;
rc.bottom = rc.top+met.tmHeight+10;
text.font->DrawTextA ( Sprite, text.Text, 300, &rc, DT_NOCLIP, text.color );
}
D3DXMATRIX mat;
D3DXMatrixTransformation2D ( &mat, NULL, 0.0, &D3DXVECTOR2 ( fScale/100, fScale/100 ),
&D3DXVECTOR2 ( rotX, rotY ), D3DXToRadian ( fAngle ), &D3DXVECTOR2 ( X, Y ) );
Sprite->SetTransform ( &mat );
Sprite->Draw ( texture.tex, NULL, NULL, NULL, diffuse );
Sprite->End ( );
if i set first ID3DXSprite::Draw() parameter to NULL, i see the text ( and obviously no texture ), but how can i show both, text and texture?
second question is, how to move a sprite, and how to point it to a specific x,y coordinates? i currently have the following:
void hxSprite::Move ( int units )
{
X -= sin ( fAngle )*units;
Y -= cos ( fAngle )*units;
}
void hxSprite::Point ( int x, int y )
{
float DX = x - X+rotX;
float DY = y - Y+rotY;
float DIST = sqrt ( (DX*DX) + (DY*DY) );
if( DIST > 0 )
fAngle = atan2f ( DX, DY );
}
both of them have weird behaviors, i believe my maths are wrong, note that fAngle is the sprite angle
thanks a lot.
-Hassan