Game Development Community

In-game cursor

by Sean H. · 07/08/2005 (7:10 am) · 24 comments

Hey hey hey everybody! This is my first resource and although it's rather short, I'm glad to finally be able to give back to the community. I spent several hours last night researching and trying to figure this out for my game and I finally came up with a solution which takes a few seconds to implement. I am no posting it here so you guys don't have to waste time figuring it out and to give back to the community which has given me so many solutions. =)

first a little background:

youll notice that the only time a cursor appears is when a GuiControl is on-screen. without any extraneous resources, a GuiControl is the only way to get a mouse cursor. However, the in-game Gui is usually a GameTSCTRL(Game Three Space Control).

for reference: fps/client/scripts/serverconnection.cs

function GameConnection::initialControlSet(%this)
{
   echo ("*** Initial Control Object");

   // The first control object has been set by the server
   // and we are now ready to go.
   
   // first check if the editor is active
   if (!Editor::checkActiveLoadDone())
   {
      if (Canvas.getContent() != PlayGui.getId())
         Canvas.setContent(PlayGui);
   }
}

this sneaky little function is called automatically by the engine right before the game begins. This is where the PlayGui is bound to the screen.

additional reference: fps/client/ui/playGui

new GameTSCtrl(PlayGui) {

   profile = "GuiContentProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 8";
   visible = "1";
   helpTag = "0";
   noCursor = true;
   

   new GuiBitmapCtrl(CenterPrintDlg) {
      profile = "CenterPrintProfile";
      etc....

we need a GameTSCTRL for in-game menus, but this particular GUI gets rid of the cursor. If we were to make this a GuiControl instead, the cursor would work but then there would be no gameplay screen.

So how do we get both a gameplay screen and a mouse cursor? We can do this by simply embedding the GameTSCTRL into a larger GuiControl.

modify fps/client/ui/playGui as follows:

new GuiControl(PlayGui){
    profile="GuiContentProfile"
    
    new GameTSCTRL(PlayGui2){
    //everything else remains the same
    };
};

Dont forget to add another " }; " at the end. In effect you are surrounding the GameTSCTRL within a GuiControl. This gives the benefit of an in-game menu with the added bonus of a mouse cursor. Best of all, the current ActionMap will still be valid with the exception of the mouse which now controls the cursor. For further reference, the default mouse cursor is defined in common/ui/defaultprofiles.cs.

I know this is simple, but I've seen a few questions about in-game cursors so I thought I'd post my findings. Happy torquing!
Page«First 1 2 Next»
#21
03/13/2007 (9:27 pm)
* Still getting use to the forum layout and realized I posted a question when this is for commenting on resources *
#22
10/20/2007 (7:44 am)
Howdy everyone.

Ok so I put this into the end of my default.bind.cs file...

moveMap.bind( keyboard, m, keycursor);
function keycursor(%val)
{
if(%val)
{
if(Canvas.isCursorOn()
CursorOff();
else
CursorOn();
}
}

and it doesn't work correctly in 1.5 TGE. I need to hold down "m" for the cursor to appear. It seems nothing I do can make it a toggle. Thanks for any help with this.
#23
10/20/2007 (7:52 am)
Heh, I knew I'd fix it right after posting... I guess it had to do with where in the default.bind.cs file the code was :shrug:

My new problem is that the cursor appears, and the second I move the mouse the cursor jumps to the center of the screen. Its quite distracting. Anyone know what might be causing this? Thanks!
#24
01/07/2009 (5:19 am)
Pretty good, though I ended up using cursorOn(); and then also noCursor = 0 :)
Page«First 1 2 Next»