Game Development Reference
In-Depth Information
GPTEditorGameObject[] gameObjects =
new GPTEditorGameObject[mUpdatedGameObjects.size()];
GPTJNILib.Initialize(sceneObjects.toArray(gameObjects));
}
These two functions are fairly straightforward; if the user touches the GUI, the HandleGUITouch function is called,
as shown in Listing 12-7.
Listing 12-7. GPTScenePlayerView Touch Functions
@Override
public boolean onTouchEvent(MotionEvent event) {
PointerCoords coords = new PointerCoords();
event.getPointerCoords(0, coords);
if(event.getAction() == MotionEvent.ACTION_DOWN)
HandleTouchDownEvent(coords.x, coords.y);
return true;
}
private void HandleTouchDownEvent(float x, float y) {
// If we touched the GUI, interact with it
Rect guiRect = new Rect(0, 0, getWidth(),
(int)((getHeight() * GUI_SCREEN_HEIGHT_PCT)));
if (guiRect.contains((int)x, (int)y))
HandleGUITouch(x, y);
}
If the user presses the play button, the mIsPlaying flag gets set to true , the timer is started, and the scene player's
Update function will continually request an up-to-date list of game objects. If the Pause button is pressed, mIsPlaying
is set to false . If the Stop button is pressed, the scene is reset directly; all game objects move back to their original
positions as shown in Listing 12-8. The Update function is shown in Listing 12-9.
Listing 12-8. GPTScenePlayerView HandleGUITouch Function
private void HandleGUITouch(float x, float y) {
Rect playPauseButtonRect =
new Rect(0, 0, getWidth() / 2,
(int)((getHeight() * GUI_SCREEN_HEIGHT_PCT)));
Rect stopButtonRect =
new Rect(getWidth() / 2, 0, getWidth(),
(int)((getHeight() * GUI_SCREEN_HEIGHT_PCT)));
if (playPauseButtonRect.contains((int)x, (int)y))
{
mIsPlaying = !mIsPlaying;
 
Search WWH ::




Custom Search