6.8.9. Method drawGameElements

The method drawGameElements (Fig. 6.15) draws the cannon, cannonball, blocker and target on the SurfaceView using the Canvas that the CannonThread (Section 6.8.14) obtains from the SurfaceView’s SurfaceHolder.

359   // draws the game to the given Canvas360   public void drawGameElements(Canvas canvas)361   {362      // clear the background363      canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(),364         backgroundPaint);                                        365 366      // display time remaining367      canvas.drawText(getResources().getString(                        368         R.string.time_remaining_format, timeLeft), 30, 50, textPaint);369 370      // if a cannonball ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.