ChaiLove API 2.1.0
love::joystick Class Reference

Provides an interface to connected joysticks. More...

#include <joystick.h>

Public Member Functions

std::vector< Joystick * > & getJoysticks ()
 Gets a list of connected Joysticks.
int getJoystickCount ()
 Gets the number of connected joysticks.
bool isDown (int joystick, int button)
 Checks if a button number is pressed on a joystick.
bool isDown (int joystick, const std::string &button)
 Checks if a button is pressed on a joystick.
Joystick * operator[] (int joystick)
 Retrieve the given joystick.

Detailed Description

Provides an interface to connected joysticks.

Member Function Documentation

◆ getJoystickCount()

int love::joystick::getJoystickCount ( )

Gets the number of connected joysticks.

Returns
The number of connected joysticks.

◆ getJoysticks()

std::vector< Joystick * > & love::joystick::getJoysticks ( )

Gets a list of connected Joysticks.

Returns
Gets a list of connected Joysticks.

◆ isDown() [1/2]

bool love::joystick::isDown ( int joystick,
const std::string & button )

Checks if a button is pressed on a joystick.

Example

if (love.joystick.isDown(0, "left")) {
love.graphics.print("Joystick is pushed LEFT", 100, 100)
}
The primary purpose of the graphics module is to draw to the screen.
Definition graphics.h:29
graphics & print(const std::string &text, int x, int y)
Prints the given text to the screen.
Provides an interface to connected joysticks.
Definition joystick.h:17
bool isDown(int joystick, int button)
Checks if a button number is pressed on a joystick.
This covers all the modules available through ChaiLove.
Definition audio.h:9
Parameters
joystickThe joystick to be checked.
buttonThe button to be checked.
Returns
True if the joystick button is pressed.

◆ isDown() [2/2]

bool love::joystick::isDown ( int joystick,
int button )

Checks if a button number is pressed on a joystick.

Parameters
joystickThe joystick to be checked.
buttonThe button to be checked.
Returns
True if the joystick button is pressed.

◆ operator[]()

Joystick * love::joystick::operator[] ( int joystick)

Retrieve the given joystick.

Example

if (love.joystick[0].isDown("left")) {
love.graphics.print("Joystick is pushed LEFT", 100, 100)
}
Parameters
joystickThe joystick index to be retrieved.
Returns
The joystick of the given player number.