📓
engine
  • Kakara Engine
  • Debugging
  • Getting Started
    • Getting the Engine
    • A New Game
    • Game Items
    • Components
    • Textures
    • Model Loading
    • The Camera
    • Player Input
      • Practical use of the Input
    • Lighting
    • User Interface
  • Scene System
    • Scene System
  • Render System
    • Extensible Render Pipeline
      • Standard Shader Format
      • Voxel Shader Format
      • Particle Shader Format
      • Lighting Shader Format
      • Custom Pipelines
  • Java Documentation
Powered by GitBook
On this page
  • Keyboard Input
  • Controller Input
  • Controller Buttons
  • Controller Axes
  • Controller Rumble
  • Special Controller Features
  • Mouse Input

Was this helpful?

  1. Getting Started

Player Input

Learn about using player input with the Kakara Engine.

PreviousThe CameraNextPractical use of the Input

Last updated 4 years ago

Was this helpful?

The Kakara Engine has many ways to handle input, in this tutorial we will only cover the basic way. The Kakara Engine supports Mouse, Keyboard, and Controllers. The basic way to handle input is through the Input utility class.

Keyboard Input

Checking for Keyboard input can be as simple as this:

if(Input.isKeyDown(KeyCode.W)){
    System.out.println("Key Pressed!");
}

That checks if a key is held being held down and executes code if it is. That if statement would be put in an update method.

There are 2 events relating to KeyInput, check out the article for more information.

Controller Input

The Nintendo Switch Pro controller will not work proper due to a bug in GLFW. See the bug report .

Like Keyboard input, the Input class can be used with Controllers. Controllers have two kinds of input: Axis and Button. Controllers also have an ID, like a controller slot on consoles. There can be 16 controllers connected at once. ControllerID.CONTROLLER_ONE is an example of an ID.

Controller Buttons

The triggers are considered axes instead of a button.

You can check if a controller button is pressed by using:

if(Input.isGamePadButtonDown(ControllerID.CONTROLLER_ONE, GamePadButton.X){
    System.out.println("The X button was pressed!");
}

Controller Axes

An axis is an input that ranges from -1 to 1. This includes things like: Left Stick, Right Stick, and the triggers.

float valueX = Input.getGamePadAxis(ControllerID.CONTROLLER_ONE, GamePadAxis.LEFT_STICK_X);
float valueY = Input.getGamePadAxis(ControllerID.CONTROLLER_ONE, GamePadAxis.LEFT_STICK_Y);

Controller Rumble

As of right now controller rumble is not supported by the Engine since GLFW does not support it yet. This feature might be added in the future.

Special Controller Features

Any special features a controller might have, like Haptic Feedback, are not supported by the Engine. You will need to add that feature in yourself.

Mouse Input

Unlike Controller and Keyboard, the Input class is not used. Instead the GameHandler contains a MouseInput class.

MouseInput mouseInput = handler.getMouseInput();
// The change in mouse position since the last frame.
Vector2d deltaPosition = mouseInput.getDeltaPosition();
// The current mouse position.
Vector2d position = mouseInput.getPosition();

if(mouseInput.isLeftButtonPressed())
    System.out.println("The left mouse button is pressed");
    
if(mouseInput.isRightButtonPressed())
    System.out.println("The right mouse button is pressed");

The code snippet above just covers a small slice of the MouseInput class.

There is an event relating to Controller Buttons, check out the article for more information.

There are several events relating to Mouse Input, check out the article for more information.

EventSystem
here
EventSystem
EventSystem