Recommended Posts

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:

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:

This is because ID3DXSprite does a few internal optimizations by default - one of these is sorting by texture. Chances are that it's drawing the text before it draws your sprite.

As for your second question, what exactly are you trying to do? To draw a sprite at a specific location, you use D3DXMatrixTransformation2D() to build a transformation matrix and call SetTransform() on your sprite object to tell it what transform to use. You have done this in your first snippet of code, so I am confused as to what your question is.

Share this post

Link to post

Share on other sites

Original post by Hassanbasilso the text cannot be a part of the sprite? then what is the sprite parameter for? oh well then, is it possible to draw text to a texture?

It can, but because of internal optimizations, it will probably draw the text before any of your sprites. There's really no reason to worry about it unless it's causing a severe performance drop, and in this case it shouldn't.

Quote:

Original post by Hassanbasilas for the second question, my sprite has a position (x,y) and an angle, using them, i want to be able to move my sprite forward and point it.

as for moving forward, lets say the angle is 0, that means it's pointing upwards, so i want to move it upwards n units, if the angle is 45, move it to top right, etc.

as for pointing, it's clear isnt it? i have an angle, when i call Point() function, i want the angle to be facing the x,y coordinates passed as parameters

If you want to move a sprite, you'll need a location and velocity. You sort of do this, but it would be easier to have separate vectors for location and velocity. Then, hxSprite::Move() becomes as simple as location += velocity;.

Polar->Rectangular coordinate formulas arex = ρ*cos(θ)y = ρ*sin(θ)You seem to have these in reverse and are subtracting them instead of adding them. I can't really see anything wrong with hxSprite::Point(). Perhaps someone else can tell you what's wrong there.

x and X are positions, I don't know if the name is misleading but why there are rotX and rotY (rotations?).

About performance, if you just want to check if x == X and y == Y, don't use sqrt that it's one of the most heavy functions you can call. And probably atan2f will check this case for you anyway (test it).

Ah and this test

if( DIST > 0 )

feels bad. DIST is a float, writing 0 like that is an integer. There may be some odd rounding behind the scenes (source of bugs or just loss of speed).

Remember to always put .0f when needed.So try

if( DIST > 0.0f )

0

Share this post

Link to post

Share on other sites

main reason for drawing text over a sprite is for the rotation, so the text can be rotated with the sprite, but if im gonna use another sprite for the text, this just..well, not neat? i really want the text to be a part of the texture, so i can even write text to object's textures, not just sprites

But the input of the sin and cos functions (remember to use sinf and cosf on floats) are radians.

About move funcion, I can't see nothing wrong but it may be that your origin and the direction of the positive axis aren't the ones you expect. Usually X axis is from left to right but Y can vary (top-down or bottom-up). Try to change the sign of Y. Or if not, please detail more "totally wrong way" ;)

it bugs out at some degree's, or lets say MOST degrees, so it doesnt move, dunno how to explain it as there are various bugs at various degree's ( it the degree is 0 or 90 or -90 or 180, it works fine, others, either doesnt move, or moves in a wrong direction )

EDIT: it seems the problem is in converting from float to int, since x/y can only be integers, sometimes sin and cos returns low values, and they become zero when they are converted, solved: