Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Engine::Input::InputManager Class Reference

A class used to handle inputs. More...

#include <InputManager.hpp>

Public Member Functions

 InputManager ()
 Default Constructor.
 
void Update ()
 Updates the input manager based on the input data available.
 
void AddAxis (const char *axis, InputParams positive, InputParams negative)
 Adds an axis to the input manager.
 
float GetAxis (const char *axis)
 Returns the value of the axis at the frame with the given name.
 
void AddInput (const char *name, InputParams input)
 Adds a single input to the input manager.
 
InputGetInput (const char *name)
 Returns the value of the input at the frame with the given name.
 

Detailed Description

A class used to handle inputs.

When creating an input manager, you can either create a button via the AddInput function, or an axis via the AddAxis function.

A Scene can have multiple InputManagers which can be used to organize inputs by object.

Example

class ExampleObject : public GameObject {
private:
Input::InputManager inputManager;
public:
ExampleScene() : Scene("ExampleScene") {
inputManager.AddAxis("Horizontal", {'d'}, {'a'});
inputManager.AddInput("Jump", {Input::KeyCodes::SPACE});
inputManager.AddInput("MouseClick", {-1, 0});
inputManager.AddAxis("Scroll", {-1, 4}, {-1, 3});
}
}
A Game Object loaded in the scene.
Definition GameObject.hpp:50
A class used to handle inputs.
Definition InputManager.hpp:44
void AddInput(const char *name, InputParams input)
Adds a single input to the input manager.
Definition InputManager.cpp:31
void AddAxis(const char *axis, InputParams positive, InputParams negative)
Adds an axis to the input manager.
Definition InputManager.cpp:20
A single node in a game scene.
Definition Node.hpp:43

Member Function Documentation

◆ AddAxis()

void Engine::Input::InputManager::AddAxis ( const char *  axis,
InputParams  positive,
InputParams  negative 
)

Adds an axis to the input manager.

This can be accessed later using the GetAxis function

Parameters
axisThe name of the axis
positiveThe positive side of the axis (If down, axis = 1)
negativeThe negative side of the axis (If down, axis = -1)

Note:

If both positive and negative are down, the axis will be set to 0 because the inputs will cancel out

◆ AddInput()

void Engine::Input::InputManager::AddInput ( const char *  name,
InputParams  input 
)

Adds a single input to the input manager.

This can be accessed later using the GetInput function

◆ GetAxis()

float Engine::Input::InputManager::GetAxis ( const char *  axis)

Returns the value of the axis at the frame with the given name.

Returns
The value of the axis between -1 and 1

◆ GetInput()

Engine::Input::Input * Engine::Input::InputManager::GetInput ( const char *  name)

Returns the value of the input at the frame with the given name.

Returns
The value of the input between 0 and 1

The documentation for this class was generated from the following files: