Best practices for making an Android game
Making an Android game is not a big deal. But making the game in the right way through which the game looks great, and performs well across as many devices as possible, is very important. The best practices should focus on the following points:
- Maintaining game quality
- Minimalistic user interface
- Supporting maximum resolutions
- Supporting maximum devices
- Background behavior
- Interruption handling
- Maintaining battery usage
- Extended support for multiple visual qualities
- Introducing social networking and multiplayer
Let's discuss these in brief here. We will elaborate on this in detail later as the book progresses.
There are millions of games available in the market, and thousands being introduced every week. So, just making a good game is not enough nowadays. Every developer should maintain their game periodically to cope with the quality of other improved games.
The developer should keep a constant eye on the reviews and complaints from the users. The game quality can be improved a lot based on this feedback. No one can predict the exact user reaction to the game before it is out in the market. So, in most cases, it is noticed that the game goes through a drastic change in design, or other means, to keep the consumer happy.
There are a few other ways to track the behavior of consumers/players. There are several tools available to do this job efficiently, such as Google Analytics, Game Analytics, Flurry, and so on. Besides these internal integrations, user comments on stores or blogs are helpful to maintain the quality of a game.
Fixing bugs in a game is another major factor in increasing the quality of the game. It is not possible to get rid of all the bugs inside the game during development. The App Store bug report tool is useful for tracking major crashes and ANRs when the game is out in the market. Besides this, the developer can use Android error reporting to track errors and bugs from real users. Android provides this feature in Android versions 2.2 and later.
Two more parameters that improve the quality of the game are stable gameplay, and consistent frame rate.
Minimalistic user interface
This is a typical design practice for Android games. A common mistake that many developers make is that they design a long and hectic user interface to take the user to the gameplay. This section should be as short as possible. The player should experience the game with minimum effort the very first time. Most users leave games because of the heavy UI interface.
Technically, a developer should take care of the device UI options like Menu, Back, and Home. These are the most common options for the Android mobile and tablet platforms. The behavior of all these options should be controlled within the game, as the user might press/touch them accidentally while playing the game. Also, there should be a quick interface to quit the game.
Basically, having a minimum user interface and fewer screen transactions saves a lot of time, which has a direct impact on gameplay sessions.
Supporting maximum resolutions
This is a very obvious point for creating a good Android game. A game must support as many resolutions as possible. Android, in particular has many different screen sizes available in the market.
Android has a series of different resolution sets:
- LDPI (approximately 120 dpi)
- MDPI (approximately 160 dpi)
- HDPI (approximately 240 dpi)
- XHDPI (approximately 320 dpi)
- XXHDI (approximately 480 dpi)
- XXXHDPI (approximately 640 dpi)
If they do not follow multiple resolution specifications, the developer can also opt for the screen compatibility option available as a last resort. However, it is recommended not to use this feature of Android, because it can reduce the visual quality significantly. This option is, by default, disabled from Android API version 11.
Supporting maximum devices
Other than the different screen sizes, Android has a variety of device configurations. Most developers filter the device list only by screen resolution, which is a bad practice. An Android game developer should always consider the target device configuration along with the resolution.
When building their applications, developers should remember not to make assumptions about specific keyboard layouts, the touch interface, or other interactive systems unless, of course, the game is restricted so that it can only be used on those devices.
Optimizing the application in terms of memory and performance is also helpful in supporting more devices. The developer should not restrict them to only a few sets of devices. Optimal use of disk space and the processor opens up the opportunity to increase the support range.
A single game application build can support more devices with some simple tricks. On Android activity launch, the developer should detect hardware information, and use that to create some sort of rules by which the entire game quality and processing speed can be controlled.
A few tasks in a game may run in the background while the main thread is running. These are called asynchronous tasks, mostly used for loading a large file or fetching something from the Internet.
Another type of background task is called services, which works even when the main application thread is not running. This is a very useful feature for communicating with the device on which the game is installed.
It is a good practice for any game developer to use these features in the game properly. A large chunk of data usually takes longer time, but it should not pause the game loop. In another scenario, asynchronous tasks are used when the game communicates with the Internet or other connectivity. This feature helps to keep the main thread running, and provides dynamic feedback.
Background services are useful for increasing the communication between the developer and user. They can provide user activity information to improve the game as well as notifying users about the latest update or information.
Interruption handling is one of the trickiest parts of game development. As we discussed earlier about the game loop, the loop pauses or, sometimes, terminates on any external interruption. In an ongoing game cycle, the interruption should not harm the gaming experience. It is a very common problem for developers that the game restarts after being interrupted. Android is most likely to kill the game activity if it remains in an idle state for a long time, or if some other activity needs provision to run. In these cases, most of the time, the player loses his/her progress.
It is good practice to save the user progress periodically to avoid any loss of data or progression. But saving data may cause lags in the game loop, and can drop the frame rate significantly. The game developer should identify the states where the data can be saved without affecting the gaming experience.
The way to handle this issue in a multi-activity application is to detect and pause/resume all the running threads. Many times, the game developer keeps running the thread, as the primary objective is just to pause/resume the game loop properly on interruption. In most cases, all of the background processes do not pause, causing unusual behavior by the game.
Maintaining battery usage
One of the reasons for the success of an Android game is power efficiency. Most likely, the Android hardware platform will be a mobile device, which has a limited source of power. So power-saving applications are always preferred.
A major chunk of the battery is consumed by rendering and network connectivity. From the gaming perspective, rendering and connectivity are both necessary. So, there is a fair chance that the game uses up a lot of power.
Most game developers focus a lot on visual appearance. It increases the graphic quality as well as battery consumption. So it is a very good practice for the developer to always focus more on the technical quality of the graphical assets. Assets should not boost up processing or rendering, as, developers often use non-optimized assets.
Another process which consumes a lot of battery is background services. These are used widely for better connectivity with consumers or for some web-based services. Technically this process pings frequently to stay connected with the desired network. Developers can control this frequency. Another way to avoid this is by killing a service which is not connected for a long time or was disconnected from the network, with the help of Android PackageManager.
In many cases, it is seen that a game becomes popular, or has a better user count than another, better-quality game, just because of lower battery consumption.
If the developers can determine that connectivity is lost, then all of the receivers except the connectivity-change receiver can be disabled using native APIs. Conversely, once the developers are connected, then they can stop listening for connectivity changes, and simply check to see if the application is online immediately before performing an update; they can then reschedule a recurring update alarm.
Developers can use the same technique to delay a download that requires higher bandwidth to complete simply by enabling a broadcast receiver, which will listen for connectivity changes, and initiate the download only after the application is connected to Wi-Fi. This significantly reduces battery use.
Extended support for multiple visual quality
This section actually starts with supporting multiple resolutions. We have already discussed multiple-size screens with different dpi. The following list is another standard that Android devices follow:
- QVGA (low PPI)
- WQVGA (medium-low PPI)
- HVGA (medium-high PPI)
- WVGA (medium-high PPI)
- SVGA (high PPI)
- VGA (very high PPI)
Creating graphics using this standard is always beneficial in order to achieve the best possible visual quality across devices. This notation mainly depends on the screen size, irrespective of the resolution. It is very common for Android devices to have the same resolution running on different screen sizes. Creating assets specially optimized for targeted devices will always help to increase the visual quality.
Introducing social networking and multiplayer
The gaming industry's style and standards are changing rapidly. Now gaming is being used for social connectivity, which is, connecting more than one real user on a single platform. Very careful use of this social element can increase the user base and retention rate significantly.
In many games, there is the possibility of more than one user being able to experience the same game state together, and to improve the game play by real-time interaction. A few board games such as Chess, Ludo, and Snakes and Ladders, are examples of such a possibility. Beside those, some real-time online multiplayer games are also at their peak.
Google has its own multiplayer features through Google Play Services. Besides popular turn-based and real-time multiplayer support, Google has also introduced a feature to connect players in close proximity on a single platform through Wi-Fi, called Google Nearby. There are many other third-party platforms that support multiplayer.