Game Development Reference
In-Depth Information
IsWithinBounds is a pretty simple method that just does a basic check to see if
the point is between the lower and upper values.
bool
PointerAxisBoundsTrigger::IsTriggered(InputManager
*input)
{
float ptrX, ptrY;
input->GetPointerPos(&ptrX, &ptrY);
bool result = _hasX || _hasY;
if (_hasX)
result &= IsWithinBounds(_x, ptrX);
if (_hasY)
result &= IsWithinBounds(_y, ptrY);
auto pressed = input->IsPointerPressed();
if (pressed)
_state = KeyState::Pressed;
else if (_state == KeyState::Pressed)
_state = KeyState::JustReleased;
else
_state = KeyState::Released;
return result && (_state == _expectedState);
}
IsTriggered is where most of the work is done, and most of this is new except for
the bit at the end that you will recognize. We begin by retrieving the pointer position
from InputManager , and then determine if bounds have been set for either axis.
We can then test the point against each set axis to determine if it is within one or
both, and from there determine if the pointer is pressed so we can check against the
expected state.
With this trigger we now have all of the required code to implement keyboard, touch,
and GamePad-based inputs for the game.
Search WWH ::




Custom Search