Upgrading the printDebuggingText method

Now we will draw lots more text but as we only want to draw it when we are debugging we will put it in the printDebuggingText method.

Delete all the code in the printDebuggingText method and replace it with the following highlighted code. Outputting debugging text to logcat is so chapter 3.

// This code prints the debugging text
public void printDebuggingText(){
   paint.setTextSize(blockSize);
   canvas.drawText("numberHorizontalPixels = "
         + numberHorizontalPixels,
         50, blockSize * 3, paint);

   canvas.drawText("numberVerticalPixels = "
         + numberVerticalPixels,
         50, blockSize * 4, paint);

   canvas.drawText("blockSize = " + blockSize,
         50, blockSize * 5, paint);

   canvas.drawText("gridWidth = " + gridWidth,
         50, blockSize * 6, paint);

   canvas.drawText("gridHeight = " + gridHeight,
         50, blockSize * 7, paint);

   canvas.drawText("horizontalTouched = " +
         horizontalTouched, 50,
         blockSize * 8, paint);

   canvas.drawText("verticalTouched = " +
         verticalTouched, 50,
         blockSize * 9, paint);

   canvas.drawText("subHorizontalPosition = " +
         subHorizontalPosition, 50,
         blockSize * 10, paint);

   canvas.drawText("subVerticalPosition = " +
         subVerticalPosition, 50,
         blockSize * 11, paint);

   canvas.drawText("hit = " + hit,
         50, blockSize * 12, paint);

   canvas.drawText("shotsTaken = " +
         shotsTaken,
         50, blockSize * 13, paint);

   canvas.drawText("debugging = " + debugging,
         50, blockSize * 12, paint);

}

This is a lengthy method but not complicated at all. We simply draw the name of each variable concatenated with the actual variable. This will have the effect of drawing the name of all the variables followed by their corresponding values. Notice that we use blockSize in the calculation to position them and for each line of text we increase by one, the amount that blockSize is multiplied by. This will have the effect of printing each line 50 pixels from the left and one underneath the other.

Run the game and you should see something like this next image.

Upgrading the printDebuggingText method

That's it for this chapter.