-
Notifications
You must be signed in to change notification settings - Fork 1
Gameoverlay
This is how the function should look with our new line of code at the end.
function PlayGui::onWake(%this) { // Turn off any shell sounds... // sfxStop( ... );$enableDirectInput = "1"; activateDirectInput();
// just update the action map here moveMap.push();
// hack city - these controls are floating around and need to be clamped schedule(0, 0, "refreshCenterTextCtrl"); schedule(0, 0, "refreshBottomTextCtrl");
schedule(100,0, updateDisplay);//our new schedule }
This schedule is a one-off call, but we want to constantly update our
display with the new values. We make this happen by calling the
schedule method again from our updateDisplay function.
STEP 2: At the end of the script page add the following new function:
function updateDisplay() { lblTime.setValue((getRealTime()/1000)); schedule(100,0, updateDisplay); }
Here we have made another call to the schedule which will give
us a loop timed at 100ms updating any statements in this function. The
first line sets the GuiTextCtrl named lblTime text content to getRealTime() which is the current time in milliseconds.
STEP 3: Next we will set up the text to display the current fps
and poly count of the scene. This is done by looking at the global
variables $fps::real and $GFXDeviceStatistics::polyCount. Add the following lines of script after the time statement:
lblFps.setValue($fps::real); lblPoly.setValue($GFXDeviceStatistics::polyCount);
Your function should now look like this:
function updateDisplay() { lblTime.setValue((getRealTime())); lblFps.setValue($fps::real); lblPoly.setValue($GFXDeviceStatistics::polyCount); schedule(100,0, updateDisplay); }
Save your script and run your project. All being well and you have no
errors, your display should show the time in ms, fps and poly count.
Next we need to count the mouse clicks. Close down your project so we
can add some more script.
STEP 4: To count our mouse clicks we need a way to tell the
system that our mouse button has been pressed. We do this in the same
way as we did for checking for a pressed key, with the bind method.
Open your game/scripts/client/default.bind.cs file for editing. At the end of this file add the following:
function mouseFire() {
// add the value of one to our “click” text control
lblClicks.setValue(lblClicks.getValue()+1); }moveMap.bind(mouse, "button0", mouseFire);
We have set the mouse button0 to call mouseFire function every time its
pressed by adding it to the bind method. Run the project and click the
left mouse button. The mouseFire() function sets the text controls body text every
time its called, this counts the mouse down and mouse up events.
To stop this and only count the mouse down even we need to modify the
function slightly. Close your project and edit the file as follows:
function mouseFire(%val) {
if(%val) { //mouse down // add the value of one to our “click” text control
lblClicks.setValue(lblClicks.getValue()+1); }else { //mouse up } }
Now the mouseFire function only counts the mouse down event. Save your files, run the project and test the mouse down counting.
In this tutorial, you learned the following concepts:
- Display text on the Game screen
- Show how to detect a mouse click
- Simple use of the schedule timer
- Show game fps and poly count
- Locate and Edit the playGui
The next Tutorial we will create a more advanced GUI window using List Controls.