VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::InputComponent Struct Reference

Component you add to your GameObject to handle input, eg. add input bindings and mouse axis bindings. More...

#include <InputComponent.hpp>

Public Member Functions

void addBinding (SDL_Scancode scancode, InputActionState state, std::function< void(float)> action)
 Adds input binding.
void addMouseAxisBinding (MouseAxis axis, std::function< void(float)> action)
 Adds axis binding.
void addGamepadButtonBinding (SDL_GamepadButton button, InputActionState state, std::function< void(float)> action)
 Adds gamepad button binding.
void addGamepadAxisBinding (SDL_GamepadAxis axis, std::function< void(float)> action)
 Adds gamepad axis binding.

Public Attributes

std::vector< InputBindingbindings
std::vector< MouseAxisBindingmouseAxisBindings
std::vector< GamepadButtonBindinggamepadButtonBindings
std::vector< GamepadAxisBindinggamepadAxisBindings

Detailed Description

Component you add to your GameObject to handle input, eg. add input bindings and mouse axis bindings.

Definition at line 58 of file InputComponent.hpp.

Member Function Documentation

◆ addBinding()

void vex::InputComponent::addBinding ( SDL_Scancode scancode,
InputActionState state,
std::function< void(float)> action )
inline

Adds input binding.

Parameters
SDL_Scancodescancode - The SDL_Scancode of the key to bind.
InputActionStatestate - The state of the key to bind.
std::function<void(float)>action - The action to perform when the key is pressed.

Example usage:

void onJump(float dt) {
player->jump(dt);
}
InputComponent* input = entity->addComponent<InputComponent>();
input->addBinding(SDL_SCANCODE_SPACE, InputActionState::Pressed, onJump);
Component you add to your GameObject to handle input, eg. add input bindings and mouse axis bindings.
void addBinding(SDL_Scancode scancode, InputActionState state, std::function< void(float)> action)
Adds input binding.

Definition at line 78 of file InputComponent.hpp.

◆ addGamepadAxisBinding()

void vex::InputComponent::addGamepadAxisBinding ( SDL_GamepadAxis axis,
std::function< void(float)> action )
inline

Adds gamepad axis binding.

Parameters
SDL_GamepadAxisaxis - The SDL_GamepadAxis to bind.
std::function<void(float)>action - The action to perform when the axis is moved.

Example usage:

void onGamepadAxisMove(float axis) {
player->GetComponent<vex::TransformComponent>().rotation.x += axis;
}
InputComponent* input = player->addComponent<InputComponent>();
input->addGamepadAxisBinding(SDL_CONTROLLER_AXIS_LEFTX, onGamepadAxisMove);
void addGamepadAxisBinding(SDL_GamepadAxis axis, std::function< void(float)> action)
Adds gamepad axis binding.
Struct containing transform data and methods.

Definition at line 130 of file InputComponent.hpp.

◆ addGamepadButtonBinding()

void vex::InputComponent::addGamepadButtonBinding ( SDL_GamepadButton button,
InputActionState state,
std::function< void(float)> action )
inline

Adds gamepad button binding.

Parameters
SDL_GamepadButtonbutton - The SDL_GamepadButton to bind.
InputActionStatestate - The state of the button to bind.
std::function<void(float)>action - The action to perform when the button is pressed.

Example usage:

void onGamepadButtonPress(float dt) {
player->jump(dt);
}
InputComponent* input = entity->addComponent<InputComponent>();
input->addGamepadButtonBinding(SDL_CONTROLLER_BUTTON_A, InputActionState::Pressed, onGamepadButtonPress);
void addGamepadButtonBinding(SDL_GamepadButton button, InputActionState state, std::function< void(float)> action)
Adds gamepad button binding.

Definition at line 113 of file InputComponent.hpp.

◆ addMouseAxisBinding()

void vex::InputComponent::addMouseAxisBinding ( MouseAxis axis,
std::function< void(float)> action )
inline

Adds axis binding.

Parameters
MouseAxisaxis - The MouseAxis to bind.
std::function<void(float)>action - The action to perform when the axis is moved.

Example usage:

void onMouseMove(float axis) {
player->GetComponent<vex::TransformComponent>().rotation.x += axis;
}
InputComponent* input = player->addComponent<InputComponent>();
input->addMouseAxisBinding(MouseAxis::X, onMouseMove);
void addMouseAxisBinding(MouseAxis axis, std::function< void(float)> action)
Adds axis binding.

Definition at line 95 of file InputComponent.hpp.

Member Data Documentation

◆ bindings

std::vector<InputBinding> vex::InputComponent::bindings

Definition at line 59 of file InputComponent.hpp.

◆ gamepadAxisBindings

std::vector<GamepadAxisBinding> vex::InputComponent::gamepadAxisBindings

Definition at line 62 of file InputComponent.hpp.

◆ gamepadButtonBindings

std::vector<GamepadButtonBinding> vex::InputComponent::gamepadButtonBindings

Definition at line 61 of file InputComponent.hpp.

◆ mouseAxisBindings

std::vector<MouseAxisBinding> vex::InputComponent::mouseAxisBindings

Definition at line 60 of file InputComponent.hpp.


The documentation for this struct was generated from the following file: