Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Maps
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

bnorton916
Neophyte

4 Posts

Posted - Jun 02 2004 :  12:57:46 PM  Show Profile  Reply with Quote
Newbie question.

Designing an app where the user need to click on an map(say US), but I need to know which state the user clicked. What is the best way to do this?

Create 50 images piece them together to form map? Another easier way?

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 02 2004 :  1:10:28 PM  Show Profile  Reply with Quote
The 50 images wouldn't work... All the images would overlap.

You could give each state a slightly diffent color, then when the user clicks the map, get the pixel color at that location. You could then use select case to find the state. That seems to be one of the easiest to me, although it may look a little weird...


Edited by - Sr. Guapo on Jun 02 2004 1:11:06 PM
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - Jun 02 2004 :  1:23:38 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Yes I agree, the color would be best or you can even use polygons to represent the maps, and then with a little math see where the point is...........but the colors are by far the easiest and most accurate, the only thing you have to worry about though is that some people still run a 16bit color depth, and any color returns, will only be accurate to the 4th one...

If you have rgb(0,1,0) it will return(0,0,0) all the way up to (0,3,0), so I would use colors by increments of 4 just to make sure, or not allow them to run the program from a 16bit color depth.

DaBooda out...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - Jun 02 2004 :  1:37:02 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Also I forgot one thing, If you do not wish your map to look like a pot of melted crayons, you can have two images, Have the one that represents the map, then the one to represent the color coded one, when the mouse moves on the main map, just check the same x and y on the color coded map... I have done this before with a game I made a long time ago, so it is pretty efficient and easy to do, you just have to create 2 maps, instead of 1.

DaBooda out...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

bnorton916
Neophyte

4 Posts

Posted - Jun 02 2004 :  2:11:12 PM  Show Profile  Reply with Quote
The color idea seem like it would work but that would be alot of different colors to look.

The two map idea seems to be an excellent one. I will try that.

Thanks for the tip.
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 02 2004 :  3:35:16 PM  Show Profile  Reply with Quote
I have seen somewhere the exact same thing you are describing, a US map where the program wants to know where the user clicked. I think I have it on a CD here, but if I'm right the code is for VB4...

Whatever. Who knows...
Go to Top of Page

bnorton916
Neophyte

4 Posts

Posted - Jun 02 2004 :  3:41:47 PM  Show Profile  Reply with Quote
Hey I am new willing to look at anything. VB4 whatever

Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 02 2004 :  7:11:40 PM  Show Profile  Reply with Quote
Can VB6 upgrade the code? I know VB .NET can supposedly upgrade my VB6 code, though I've never got it to work quite right...
Go to Top of Page

ken_foust@hotmail.com
Neophyte

USA
3 Posts

Posted - Jun 02 2004 :  7:43:14 PM  Show Profile  Reply with Quote
The color idea is short and sweet, but you may run into problems with people's palettes. Instead, create regions for all 50 states, then all you have to do is see if the point is in the region. I often use this in games that require irregular shaped spaces.
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - Jun 02 2004 :  7:52:02 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
palletes? isn't rgb value (0,4,0) the same on all computers? Is there something I do not know about? Honestly, I have never heard of such a thing.... I know that you can set a pallete in the form properties, but that should be the same pallete for all computers...

Dabooda out...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

bnorton916
Neophyte

4 Posts

Posted - Jun 02 2004 :  7:52:47 PM  Show Profile  Reply with Quote
Regions also sound good. A
ny tutorial that you know of that explain regions?

Do you create regions in you photo editor or vb? both?

Go to Top of Page

Brykovian
Bryk the Cheese Slayer!

USA
58 Posts

Posted - Jun 02 2004 :  8:58:55 PM  Show Profile  Visit Brykovian's Homepage  Click to see Brykovian's MSN Messenger address  Reply with Quote
I did exactly this type of program back a few years ago (coded in BlitzBasic) ... I setup a series of points (X,Y pixel locations) on the map picture and assigned each point to a state. Basically, the points were located just inside that state's side of the border at major border junctions. I think I had around 300 points defined on the map. The bigger, more rectangular western states needed fewer points than the small, lumpy eastern states ...

In any case, when the user was moving his cursor around, I'd get the cursor's X,Y and find the closest point in the list to it -- that state won. It worked a treat.

-Bryk

www.mwgames.com
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 02 2004 :  9:09:30 PM  Show Profile  Reply with Quote
That sounds much better than my idea... honestly, I've never done this sort of thing, that was just the first idea that popped into my head...
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 03 2004 :  01:10:13 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Yeah, you'll have problems if you use the colored image format. Using regions are pretty easy.

  
'The x,y coordinate are pixel coordinates, not twips.
Type POINTAPI  
        x As Long
        y As Long
End Type
' PolyFill() Modes
Const ALTERNATE = 1  
Const WINDING = 2  
Const POLYFILL_LAST = 2  
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
  
Public Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Public Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  
Public Regions(50) As Long
  
'Init Regions
Public Function InitRegions()  
Dim pnt() As POINTAPI  
ReDim pnt(0 To 5)  
pnt(0).x = 31: pnt(0).y = 111  'This should be the outline of a state.  
pnt(1).x = 60: pnt(1).y = 118  
pnt(2).x = 88: pnt(2).y = 111  
pnt(3).x = 72: pnt(3).y = 83  
pnt(4).x = 59: pnt(4).y = 87  
pnt(5).x = 47: pnt(5).y = 83  
Regions(1) = CreatePolygonRgn(pnt(0), 6, WINDING)  
[point data]  
ReDim pnt(0 To 23)  
Regions(2) = CreatePolygonRgn(pnt(0), 24, WINDING)  
[point data]  
ReDim pnt(0 To 10)  
Regions(3) = CreatePolygonRgn(pnt(0), 11, WINDING)  
etc...  
End Function
  
Public Function UnloadRegions()  
' you must unload the regions so that you dont' leak memory.
Dim N as Long
For N = 1 to 50  
Call DeleteObject(Regions(N))  
Next
  
Public Function CheckHit(x As Long, y As Long) As Long
Dim nt As Long, ht As Long
  
CheckHit = -1 'no hit.  
  
For nt = 1 To 50  
   ht = PtInRegion(Regions(nt), x, y)  
   If ht = 1 Then
        CheckHit = nt 'return index of region where there is an intersection.  
   End If
Next
'function will return -1 if there is no hit, otherwise a number from 1 to 50  
End Function
  
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 03 2004 :  8:51:54 PM  Show Profile  Reply with Quote
The reason I liked the color idea was it was so easy. You didn't have to enter a thousand little coordinates to define all the states. This way is much more "professional" and will work alot better than the colors idea though..
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - Jun 03 2004 :  9:35:38 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
I am still confused on the different pallete argument... I am probably lacking something in knowledge on this area, but could anybody clarify that for me... I am curious...

DaBooda Out...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 3.5 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.