|
-
Apr 1st, 2006, 12:47 PM
#1
Thread Starter
Lively Member
Detecting which card was clicked with cards.dll?
Does anyone have any idea how I can detect which card the user clicked on a card game when using cards.dll?
I cannot figure out how because it is not an actual object on the form but is drawn with the OnPaint event.
http://www.vbforums.com/showthread.p...46#post2417446
-
Apr 1st, 2006, 02:03 PM
#2
Re: Detecting which card was clicked with cards.dll?
i dunno what you're doing. But if you have cards drawn on the form and you want to figure out which is clicked, then you need to put some code in the Form's click event. Then you can do hit testing. You can check the mouse coordinates of the click and see if those coordinates fall inside a certain card or not.
To make it easier you can declare a Region (System.Drawing.Region) variable for each card you have. You can define the cards' regions in each variable, and on the form_click event you can call each region's IsVisible (float x, float y) method using the clicked mouse coordinates.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Apr 1st, 2006, 02:07 PM
#3
Thread Starter
Lively Member
Re: Detecting which card was clicked with cards.dll?
Thanks for the help.
I am trying to write a card game.
The problem is some cards over lap eachother and some you need to drag so im not exactly sure on how to do that but Im still thinking. I figured thats what I would have to do but seems like a bunch to keep track of. I was just wondering if there was an easier way.
-
Apr 1st, 2006, 03:10 PM
#4
Re: Detecting which card was clicked with cards.dll?
Just create a rectangle for each of the cards you draw, then test the mouse coordinates against each rectangle (most recently drawn card's rect first, and then the second most recent and so on) until you find one that the mouse clicked inside, thats the card that got clicked on.
I don't live here any more.
-
Apr 1st, 2006, 08:13 PM
#5
-
Apr 2nd, 2006, 09:43 PM
#6
Re: Detecting which card was clicked with cards.dll?
I would use an structure with a rectangle, this structure should contain more variables also. You can use Contains method of the rectangle, it returns True when the X,Y coordinates passed are inside.
I use regions when the figure is going to be transformed (scaled/rotated..), else a rectangle should be enough.
Last edited by jcis; Apr 2nd, 2006 at 09:52 PM.
-
Apr 3rd, 2006, 11:04 AM
#7
Re: Detecting which card was clicked with cards.dll?
As an alternative approach, you could make the cards a custom control, which would take care of the hit testing for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|