Posted on 28 Sep 2019
This is the eleventh article of the Android Game Programming series. Starting from this article we will begin to add very significant classes to our Game Framework.
First, we will add the Graphics interface that will manage the graphics services such as drawing bitmaps, points, lines, rectangles, and more. The bitmaps are managed by the Pixmap interface created from a file using the newPixmap API. This API also requires you to specify the bitmap format (PixmapFormat):: ARGB8888, ARGB4444, RGB565.
The newPixmap and drawPixmap methods will take care of loading the bitmap into memory and draw it on video. The first method, we will encapsulate the code of loading the bitmap discussed here, in the second one we will support the drawBitmap method of class Android Canvas.
In the graphics management, a basic role is played by the Screen interface which represents the single screen of the video game.
Creating a video game is a bit like making a movie. First, there is the storyline, that is the basic idea of what the video game will do. Afterward, it is necessary to write the script. In our case, it is a sheet where we draw the video game screenshots and events to switch from one to another.
The following image shows, for example, the screens that we will implement in this article.
As you can see the first screen is Loading Screen which is a dummy screen in which we only worry about loading all the video game assets into memory. In this case, there is just the bitmap startscreen.png. In the future, this screen could be made visible showing a progress bar that will report the loading progress. As this processing is very fast today we will avoid complicating unnecessarily our interface. Once all the assets have been loaded, the control will switch to the Start Screen on which we will show the bitmap already discussed here.
We define the package org.androidforfun.droids.view where we will put the two screens mentioned above. In the package, we add the Assets class which will contain the pointers to all the assets of our video game:
We will then define the LoadingScreen class in which we will implement the update method:
The method loads the assets and the scores saved on external memory, then it passes the control to StartScreen class. The StartScreen class we will implement only the draw method in which we will draw the bitmap on screen: