Hello,
I'm trying to use DirectX 9.0c to create a small game. Although drawing sprites on screen is not a problem, I can't find any information about how to make a drawn sprite respond to simple events, such as mouse click etc.
Does anyone know how to do it?
I would appreciate some advice.
Thanks.
I don't use DirectX, but I think the idea can be summarized as follows:
1) Determine when a mouse click event occurs.
2) Get the screen coordinates of the mouse cursor position (in pixels) when that happens.
3) Translate the pixel coordinates into the coordinates of your game. For instance, if
screen is 640 x 480
game coordinates are 0 <= x <= 4 , 0 <= y <= 3,
mouse coordinates = (300,100),
Then the game coordinates of the mouse can be obtained by linear scaling:
(300/640)*4 = 1.875
(100/480)*3 = 0.625
Note that this step can be skipped if your game coordinates equal your screen pixel coordinates.
4) Based upon the game coordinates of the mouse and whether or not there is a sprite there, do something or don't do something.
5) If you need direction / speed of the mouse to decide what to do, then you'll probably want to capture the mouse coordinates twice and take the difference. That gives you both direction and speed (according to the time between samplings).
I can't give you specific on the DirectX platform on how to find the information, but you can get all of these things in win32. I hope that it helps provide an outline to get you started. -- Paul