Introduction to Game Input and Events in Quorum

In this tutorial, we will learn about using player input and the game engine’s event system. With these tools, our games will be able to react to mouse and keyboard input, as well as to colliding game objects.

Input Polling

The first method we will discuss for getting player input is known as polling . Polling is a technique which involves regularly checking the current state of the mouse or keyboard to see if the player is giving us any input.

To do this in the Quorum Game Engine, we must include the InputMonitor library with the statement use Libraries.Game.InputMonitor. If we want to monitor keyboard input, we will also include the KeyboardEvent library with the statement use Libraries.Interface.Events.KeyboardEvent.

To see input polling in action, we will use a sample program which will play a sound when we press the spacebar on the keyboard or when we click inside the screen. To download a sample project that includes audio files, click here.

To begin with this sample, let’s start by looking at the objects we will use in our program.

InputMonitor monitor
KeyboardEvent keys
Audio keySound
Audio mouseSound

We put our InputMonitor in the Update action because we want to check (poll) the status of the inputs at every frame. This is where we test for input, and react accordingly.

   action Update(number seconds)
       // If the user is currently clicking the mouse, play a sound.
        if monitor:IsClicked()
            mouseSound:Play()
        end

       // If the user is pressing the spacebar, play a sound.
        if monitor:IsKeyPressed(keys:SPACE)
            keySound:Play()
        end
    end

The two if statements are where we check for input. In if monitor:IsClicked() we ask the InputMonitor to check if any of the mouse buttons are currently being held down. If any of them are, we will enter the code inside the if block.

Then we reach if monitor:IsKeyPressed(keys:SPACE) . The InputMonitor action IsKeyPressed will test if a particular key on the keyboard is being held down. Inside the action, we have to tell Quorum which key we want to test, so we give it the value of SPACE from the KeyboardEvent class. To see the names of all the keys refer to the KeyboardEvent documentation.

These two actions are enough to test for input from both mouse and keyboard, but the InputMonitor has other actions to poll for other kinds of information, such as the current location of the mouse. For full details on what an InputMonitor can do, see its documentation page here.

Try it out below:

Try the above code block.

Next Tutorial

In the next tutorial, we will discuss Keyboard Events in Quorum, which describes How to use keyboard events in our games..