Game Development Community

dev|Pro Game Development Curriculum

Compass and Map Gui

by Ryan Ackley · 01/22/2002 (3:05 pm) · 10 comments

Download Code File

This is the friutation of some tweaking done by myself and a few others in the forums to get a compass working in game. Original code is from nohbdy, fix for the updated engine by david doughner, and im sure others are in there. if i missed you, sorry!

Anyhow, unzip guicompassctrl.cc and .h to engine/game/gui. Add to your project and rebuild the app. Unzip the png to a directory you feel appropriate. Run your app. upon entering a level, hit f10 to bring up the gui editor. Add a new gui control, picking guicompassctrl. In the bitmap field, enter the directory of the png (mine is fps/data/textures/compass.png). Hit apply. Viola. It may not be the prettiest, but it works just fine ;)


Part 2: Map

I felt that a compass would be useless unless you had some sort of way to use the info. So, i cooked up a method to display a map bitmap that shows the user info needed to be able to use the compass in a useful manner. First off, i made a texture, map.jpg, and put in in my /data/textures directory. Secondly, i went to fps/client/config.cs and added these lines at the bottom:
moveMap.bindcmd(keyboard, "t", "", "MapGui.toggle();");

thirdly, i copied client/playerlistgui.gui and renamed it mapgui.gui i did a find-replace for playerlist and replaced it with map, and added this function at the end:
function MapGUI::toggle(%this) 
{ 
if (%this.isAwake()) 
Canvas.popDialog(%this); 
else 
Canvas.pushDialog(%this); 
}

upon entering the game and hitting f-10, i switched to my new mapgui and made a guibitmapctrl and set the bitmap to be my map. i also changed the guitextctrl to read "map" instead of players, and i resized some stuff to look right. simple as that.
--edit:( 1/32/02 9 pm EST)
you also need to add
exec("./ui/mapGui.gui");
in fps/client/init.cs

--/edit

Fallacies:
1) Yes, I only have one map in my game right now, so i really didnt feel the need to be able to have different maps bitmaps for different levels, as i dont have any more than one level. If anyone needs this, as im sure some will, Ill cook it up and update this snippit.

2) Thanks to bruce wallace for this fix!

good luck and good coding
ryan

#1
01/22/2002 (4:44 pm)
To toggle your map you could try something like this.
First you would create a .cs file for your gui.
Then add:
function MapGUI::toggle(%this)
{
if (%this.isAwake())
Canvas.popDialog(%this);
else
Canvas.pushDialog(%this);
}

Then in your Default.bind.cs under this line:
moveMap.bindcmd(keyboard, "F2", "", "PlayerListGui.toggle();");
add a line with the name of your GUI control.

moveMap.bindcmd(keyboard, "H", "", "MapGui.toggle();");

Delete the dso for default.bind, and if all goes well you have a toggling GUI.

I used playerListGUI as a model for this.

Hope that helps.
#2
01/23/2002 (6:25 am)
Yeah, i was just using a bitmapctrl in playgui.gui, maybe a seperate gui would be better... ill keep you updated as to what i come up with

--edit--
fixed fallacy #2
ryan
#3
01/24/2002 (9:00 pm)
Here's another addition you'd pry want to have since not everyone wants to be using 64x64 textures (like the default image given)

The existing code already scales the compass bitmap to the object's "window", but it doesnt' change the compass pointer.

Find these lines in guiCompassCtrl.cc
pointA.x = 25  * pointA.x;

pointA.y = 25 * pointA.y;

Replace them with:
pointA.x = 0.390625 * mBounds.extent.x * pointA.x;

pointA.y = 0.390625 * mBounds.extent.y * pointA.y;

This code will scale the compass pointer to fit when the gui object is resized (but it still sticks to the "route" that it's matched to in the default png provided. Of course, that's not something you can deal with variables... mainly since it's an arbitrary black circle you want the line to match up with)

Anyway, I am working on implementing a "Line of Sight" Compass that draws an arc on a compass to show what areas you are looking at.

It will be based off of the code here, and I will post it in the comments as soon as I have it done (I should have the simple version done within an hour pending my sleepiness)
#4
01/27/2002 (9:27 am)
Posted an update to this by matt webster. Has a bunch of neato things. read notes.txt to see what hes got.
ryan
#5
01/27/2002 (11:52 am)
nice the work on this, good to see iterative development of a feature.

just added the new files to my project and rebuilt, and am not seeing the ctrl class in my selection dialogues, also my old compass has disappeared.

any ideas, anything else I should do before firing up the gui editor?

mm
#6
01/27/2002 (1:35 pm)
If done right this will automatically be added to the drop down list in the gui editor, here are three things to try before tearing out your hair or screaming and scaring the dog.

1. Make sure you put it in engine/gui folder.
2. Make sure you've added it to both Torque LIB and Torque SDK projects
3. Neither of those do it... do a full rebuild.

I've found that after adding a .cc file to the project it forces a full rebuild, but if that isn't the case then I'd do one manually.

Try to build the torque lib first after adding this file, then build the sdk.

I'll be on here for a few more hours, so if you have other questions just ask. I'm glad to be able to help the GG community with my meager skills hehe.
#7
01/27/2002 (5:28 pm)
Yeah, im glad we have got some people working to get this one to where its a good addition with some real cool features. i can think of 5 people off of the top of my head that have worked to some extent on this one, and i know its something a lot of projects would be interested in. I havnt tried matts new and improved version of it yet, but weve talked over email and he has some cool things in it. Email him if you have any problems with the newest version of it.
ryan
#8
01/29/2002 (5:25 pm)
I've successfully coded an image-based compass gui control.

See a screenshot of it in my .plan, but I don't plan on releasing a tutorial or source code just yet since Phil Carlisle was the person who wrote the bitmaprotate function for dgl.cc and I just applied it to my gui control.
#9
01/11/2004 (9:24 pm)
Hey I am encountering a problem. I successfully added the compassCtrl, but the bitmap of the compass is not showing up for some reason. My path is: "starter.racing/client/ui/compass.png", and it was inputted correctly, yet I still don't see it.

Advice is much appreciated. Thanks.
#10
02/28/2006 (6:11 am)
Hi all,
This control is working well and showing the directions correctly, but there is a problem i am facing in my
game.After moving some distance, if I stops some where and move the camera up or down( i am not pressing left or right movement keys nor the forward and backward keys) the needle of the compass changes it direction from its current direction,though i am changing the directions.The needle moves few degress up or down.
Can any body help me out of this problem. Any type of suggestions are welcomed. If any one can explain the factors it is using to render direction then it would be highly usefull.

Thanks in Advance
Regards.