U4DEngine::U4DJoyStick class

The U4DJoyStick class controls the joystick entity.

Base classes

class U4DEngine::U4DEntity
The U4DEntity class is a Super-Class for all the entities in a game, such as 3D models, buttons, fonts, etc.

Constructors, destructors, conversion operators

U4DJoyStick(std::string uName, float xPosition, float yPosition, const char* uBackGroundImage, float uBackgroundWidth, float uBackgroundHeight, const char* uJoyStickImage, float uJoyStickWidth, float uJoyStickHeight)
Class constructor.
~U4DJoyStick()
Class destructor.

Public functions

void render(id<MTLRenderCommandEncoder> uRenderEncoder) virtual
Renders both the background image and the joystick at its new position.
void update(double dt) virtual
Updates the state of joystick.
void action()
Informs the callback pointer to call the appropriate method.
void setJoyStickWidth(float uJoyStickWidth)
Set the width texture of the joystick.
void setJoyStickHeight(float uJoyStickHeight)
Set the height texture of the joystick.
auto getJoyStickWidth() -> float
Get the joystick texture width.
auto getJoyStickHeight() -> float
Get the joystick texture height.
void setJoyStickBackgroundWidth(float uJoyStickBackgroundWidth)
Set the background texture width.
void setJoyStickBackgroundHeight(float uJoyStickBackgroundHeight)
Set the background texture height.
auto getJoyStickBackgroundWidth() -> float
Get the texture background width.
auto getJoyStickBackgroundHeight() -> float
Get the texture background height.
auto changeState(INPUTELEMENTACTION uInputAction, U4DVector2n uPosition) -> bool virtual
Changes the state of the joystick.
void setDataPosition(U4DVector2n uData)
Sets the computed position of the joystick.
auto getDataPosition() -> U4DVector2n
Gets the computed position of joystick.
void setDataMagnitude(float uValue)
Sets the magnitude position of the joystick.
auto getDataMagnitude() -> float
Gets the magnitude position of the joystick.
auto getIsActive() -> bool
Get if the joystick is currently active.
void setCallbackAction(U4DCallbackInterface* uAction)
Initializes the callback interface.
void setControllerInterface(U4DControllerInterface* uControllerInterface)
Initializes the controller interface.
auto getDirectionReversal() -> bool
Did the user reverse the joystick movement.

Public variables

U4DCallbackInterface* pCallback
Pointer to the callback object.
U4DControllerInterface* controllerInterface
Pointer to the controller interface.
U4DImage backgroundImage
background U4DImage entity for joystick
U4DImage joyStickImage
U4DImage entity for joystick.
U4DVector2n dataPosition
joystick data position
float dataMagnitude
magnitude of data position. This is normalized
U4DVector2n originalPosition
original center position of the joystick texture
U4DVector2n currentPosition
current position of joystick texture
U4DVector2n centerBackgroundPosition
position of joystick background texture image
U4DVector2n centerImagePosition
position of joystick texture image
float backgroundImageRadius
radius of joystick background texture
float joyStickImageRadius
radius of joystick texture
bool isActive
Is the joystick currently being touched or moved.
bool directionReversal
Did the joystick do a sudden reverse in direction.

Function documentation

U4DEngine::U4DJoyStick::U4DJoyStick(std::string uName, float xPosition, float yPosition, const char* uBackGroundImage, float uBackgroundWidth, float uBackgroundHeight, const char* uJoyStickImage, float uJoyStickWidth, float uJoyStickHeight)

Class constructor.

Parameters
uName name of joystick
xPosition x-axis position
yPosition y-axis position
uBackGroundImage background joystick texture name
uBackgroundWidth background texture width
uBackgroundHeight background texture height
uJoyStickImage joystick texture name
uJoyStickWidth joystick texture width
uJoyStickHeight joystick texture height

creates the state manager and sets the texture for the joystick and translates it to the assigned position

void U4DEngine::U4DJoyStick::update(double dt) virtual

Updates the state of joystick.

Parameters
dt game tick

The state manager updates the state of the joystick. The states are either idle, active or released

void U4DEngine::U4DJoyStick::action()

Informs the callback pointer to call the appropriate method.

The method the callback pointer calls is set up during the initialization of the controller. This is set up by the user.

void U4DEngine::U4DJoyStick::setJoyStickWidth(float uJoyStickWidth)

Set the width texture of the joystick.

Parameters
uJoyStickWidth width

void U4DEngine::U4DJoyStick::setJoyStickHeight(float uJoyStickHeight)

Set the height texture of the joystick.

Parameters
uJoyStickHeight height

float U4DEngine::U4DJoyStick::getJoyStickWidth()

Get the joystick texture width.

Returns width of texture

float U4DEngine::U4DJoyStick::getJoyStickHeight()

Get the joystick texture height.

Returns height of texture

void U4DEngine::U4DJoyStick::setJoyStickBackgroundWidth(float uJoyStickBackgroundWidth)

Set the background texture width.

Parameters
uJoyStickBackgroundWidth texture width

void U4DEngine::U4DJoyStick::setJoyStickBackgroundHeight(float uJoyStickBackgroundHeight)

Set the background texture height.

Parameters
uJoyStickBackgroundHeight texture height

float U4DEngine::U4DJoyStick::getJoyStickBackgroundWidth()

Get the texture background width.

Returns texture width

float U4DEngine::U4DJoyStick::getJoyStickBackgroundHeight()

Get the texture background height.

Returns texture height

bool U4DEngine::U4DJoyStick::changeState(INPUTELEMENTACTION uInputAction, U4DVector2n uPosition) virtual

Changes the state of the joystick.

Parameters
uInputAction touch state. that is moved or released
uPosition touch position

The state manager changes the state of the joystick to either active or released depending on the touch

void U4DEngine::U4DJoyStick::setDataPosition(U4DVector2n uData)

Sets the computed position of the joystick.

Parameters
uData computed data

This data is computed taking into account the current touch position, location of joystick and texture radius

U4DVector2n U4DEngine::U4DJoyStick::getDataPosition()

Gets the computed position of joystick.

Returns computed data

This data is computed taking into account the current touch position, location of joystick and texture radius

void U4DEngine::U4DJoyStick::setDataMagnitude(float uValue)

Sets the magnitude position of the joystick.

Parameters
uValue magnitude

This is computed by subtracting the current position of the joystick and the position of the background texture

float U4DEngine::U4DJoyStick::getDataMagnitude()

Gets the magnitude position of the joystick.

Returns magnitude of data

This is computed by subtracting the current position of the joystick and the position of the background texture

bool U4DEngine::U4DJoyStick::getIsActive()

Get if the joystick is currently active.

Returns true for active. false for released or idle

void U4DEngine::U4DJoyStick::setCallbackAction(U4DCallbackInterface* uAction)

Initializes the callback interface.

Parameters
uAction callback interface object

The callback is set during the controller initialization by the user. It sets which method to call if there is an action detected on the joystick

void U4DEngine::U4DJoyStick::setControllerInterface(U4DControllerInterface* uControllerInterface)

Initializes the controller interface.

Parameters
uControllerInterface controller interface object

The controller interface for joystick is usually the touch controller (U4DTouchController)

bool U4DEngine::U4DJoyStick::getDirectionReversal()

Did the user reverse the joystick movement.

Returns true if a reversal in direction did occur

Variable documentation

U4DCallbackInterface* U4DEngine::U4DJoyStick::pCallback

Pointer to the callback object.

This callback is used to inform the button which method to call upon pressed

U4DControllerInterface* U4DEngine::U4DJoyStick::controllerInterface

Pointer to the controller interface.

Usually the controller interface for button is the touch interface