Game Development Reference
In-Depth Information
// Character move
void IN_Move (usercmd_t *cmd)
{
// to look
IN_MouseLook(cmd);
// to move
//IN_MouseMove(cmd);
}
When the user drags a finger across the screen, the
onTouchEvent
in the GL view fires. This event
receives motion event information such as an action:
ACTION_DOWN
,
ACTION_UP
, or
ACTION_MOVE
,
depending on the type of motion. Because the native engine runs in a separate thread,
onTouchEvent
uses the built-in sub
queueEvent
to process the action safely into the game thread.
When the finger goes down (
ACTION_DOWN
), the XY coordinates of the press are recorded. When
the finger lifts up (
ACTION_UP
), the XY coordinates are reset to 0. When the finger is dragged
(
ACTION_MOVE
), the delta coordinates (DX, DY) are calculated, and if they exceed a threshold value
(30 pixels in this case), they are sent to the engine by consumption using JNI. This requires the
native method
int mouseMove(int deltaX, int deltaY)
in
Natives.java
and its C counterpart
Java_quake_jni_Natives_mouseMove
. The C implementation of
mouseMove
simply records the
values of delta XY coordinates to be processed by the video driver.
There is one important function in the video driver that processes movement:
IN_Move
.
Within this function, you use a mouse handler,
IN_MouseMove
, to control the pitch and yaw of
the character in 3D space. More details on this will be explained in the following sections.
Game Startup Activity
This is the final piece of the puzzle, the main entry point to the app: the game activity
(see Listing 6-9). Its job is to do the following:
Create an instance of the view
QuakeView
.
Set a renderer with a set of string arguments that will be sent to the
engine at startup.
QuakeView
as the content that will start the rendering process and
begin the game!
Set
Listing 6-9. Main Startup Activity
public class QuakeActivity extends Activity {
QuakeView mQuakeView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
mQuakeView = new QuakeView(this);