Game Development Reference
In-Depth Information
19. For each found axis, we read the value:
if ( Axis && Pressed )
{
this->ReadAxis( Axis, Pos );
FPushedAxis[ContactID] = Axis;
}
}
}
How it works...
We declare a global variable, which holds the state of our joystick:
ScreenJoystick g_Joystick;
In the OnStart() method, we add two axes and a single button:
float A_Y = 414.0f / 512.0f;
sBitmapAxis B_Left;
B_Left.FAxis1 = 0;
B_Left.FAxis2 = 1;
B_Left.FPosition = vec2( 55.0f / 512.f, A_Y );
B_Left.FRadius = 40.0f / 512.0f;
B_Left.FColor = vec4( 0.75f, 0.75f, 0.75f, 0.0f );
sBitmapButton B_Fire;
B_Fire.FIndex = ID_BUTTON_THRUST;
B_Fire.FColor = vec4( 0 );
g_Joystick.FAxisDesc.push_back( B_Left );
g_Joystick.FButtonDesc.push_back( B_Fire );
Then, we initialize the joystick and reset its state:
g_Joystick.InitKeys();
g_Joystick.Restart();
Later in the code we can use the results of g_Joystick.GetAxisValue to ind out the
current axis value, and g_Joystick.IsPressed to see if the key is pressed.
 
Search WWH ::




Custom Search