Game Development Reference
In-Depth Information
// draw game objects
for (int i = 0; i < mUpdatedGameObjects.size(); ++i)
{
GPTGameObject obj = mUpdatedGameObjects.get(i);
paint.setColor(obj.color);
c.drawCircle(obj.x, obj.y, OBJECT_RADIUS, paint);
}
// Draw UI
paint.setColor(Color.GRAY);
Rect rect = new Rect(0, 0, getWidth(),
(int)(getHeight() * GUI_SCREEN_HEIGHT_PCT));
c.drawRect(rect, paint);
String playPauseString = mIsPlaying ? "Pause" : "Play";
Rect strBounds = new Rect();
paint.setColor(Color.WHITE);
paint.setTextSize(30);
paint.setTextAlign(Align.CENTER);
paint.getTextBounds(playPauseString, 0,
playPauseString.length(), strBounds);
c.drawText(playPauseString, getWidth() / 4,
((getHeight() * GUI_SCREEN_HEIGHT_PCT) +
(strBounds.bottom - strBounds.top)) / 2, paint);
paint.setColor(Color.BLACK);
c.drawLine(getWidth() / 2, 0, getWidth() / 2,
(getHeight() * GUI_SCREEN_HEIGHT_PCT), paint);
String stopStr = "Stop";
strBounds = new Rect();
paint.setColor(Color.WHITE);
paint.setTextSize(30);
paint.setTextAlign(Align.CENTER);
paint.getTextBounds(stopStr,0,stopStr.length(),strBounds);
c.drawText(stopStr, getWidth() - (getWidth() / 4),
((getHeight() * GUI_SCREEN_HEIGHT_PCT) +
(strBounds.bottom - strBounds.top)) / 2, paint);
// Force re-draw
postInvalidate();
}
The first thing that happens, even before drawing, is updating the game objects with results from the script
engine. Then, along with the GUI elements, all the objects are drawn. Finally, the postInvalidate function call makes
sure onDraw is called again.
Good news: this function marks the last of the Java code! You are now ready to move on to native C/C++ with the
scripting engine implementation.
Search WWH ::




Custom Search