473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DirectX 9 - problem with sprites

6
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.
Jan 21 '07 #1
2 3490
macklin01
145 100+
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
Jan 21 '07 #2
Paulos
6
Good point, it will work for sure, however I'm afraid that checking cursor coordinates for a huge number of sprites could visibly slow down the application.
But I'm going to try this method of course.
Thank you for your reply.
Jan 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: twoeyedhuman1111 | last post by:
Okay, I have this sample code: class a; class b; class b { public: private:
7
by: kastillo | last post by:
Im trying to install directx 9.0 c , but i simply cant . When i run the installer it just says " The installed components are ready to use". This is the report on directx.log : 09/10/05...
6
by: ammd | last post by:
Hi, I installed Microsoft DirectX 9.0 SDK (Summer 2004) but when I create a project and try to add the necessary references I can't find them. Does anybody know where to look for them? BTW, I have VS...
2
by: jpuopolo | last post by:
All: Does anyone have a sample (or a quick explanation) of creating a simple sprite with C#? I want to write a simple game for my children. Is it as simple as creating a PNG w/ a transparent...
9
by: Mike P | last post by:
Problems, problems... Im trying to create DirectX Projects within C# and to also look at the latest DirectX C# Samples. I have just installed MS Visual C# .net Standard Edition on my Windows...
0
by: Harvey Cohen | last post by:
Hello all, I have some C# code that implements calls to DirectX.DirectSound. It compiles under both VS .NET 2003 and VS 2005 and runs under VS .NET 2003 and VS 2005 on a Compaq laptop (Windows...
14
by: Jessica Weiner | last post by:
I am writing an application in C# which need to plot graphs and simple shapes (polygons, circles, squares etc). Which library is better for this purpose and why? Thanks.
1
by: thesayan | last post by:
hello, i am attempting to translate some code from vb6 into vb 2005 that draws sprites from graphics designs. i am having trouble on the form trying to draw to back buffer surface. 'vb6 code ...
11
by: raylopez99 | last post by:
I just downloaded the apparently free SDK for DirectX 9, all 200+ MB of it, but as I read about WPF I wonder: is DirectX obsolete? Should I even bother learning how to use it? After all, the end...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.