34,79 €
Gaming in android is an already established market and growing each day. Previously games were made for specific platforms, but this is the time of cross platform gaming with social connectivity. It requires vision of polishing, design and must follow user behavior. This book would help developers to predict and create scopes of improvement according to user behavior.
You will begin with the guidelines and rules of game development on the Android platform followed by a brief description about the current variants of Android devices available. Next you will walk through the various tools available to develop any Android games and learn how to choose the most appropriate tools for a specific purpose.
You will then learn JAVA game coding standard and style upon the Android SDK. Later, you would focus on creation, maintenance of Game Loop using Android SDK, common mistakes in game development and the solutions to avoid them to improve performance. We will deep dive into Shaders and learn how to optimize memory and performance for an Android Game before moving on to another important topic, testing and debugging Android Games followed by an overview about Virtual Reality and how to integrate them into Android games.
Want to program a different way? Inside you’ll also learn Android game Development using C++ and OpenGL. Finally you would walk through the required tools to polish and finalize the game and possible integration of any third party tools or SDKs in order to monetize your game when it’s one the market!
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 441
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2016
Production reference: 1120816
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-586-0
www.packtpub.com
Author
Avisekhar Roy
Reviewer
Attilio Carotenuto
Commissioning Editor
Edward Gordon
Acquisition Editor
Rahul Nair
Content Development Editor
Anish Sukumaran
Technical Editor
Taabish Khan
Copy Editors
Sonia Mathur
Karuna Narayanan
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Graphics
Disha Haria
Production Coordinator
Melwyn Dsa
Cover Work
Melwyn Dsa
Avisekhar Roy is a B.Tech engineer in computer science. He has had a passion for coding since his school days. However, he had no plans to become a game programmer. His fate landed him in the gaming industry in 2010. Since then, he fell in love with game development.
Avisekhar has worked in many formats of game development environment, ranging from small companies and individual studios to corporate companies and full-scale game development studios. He recently started his own gaming start-up in 2016 and is currently working on games for the mobile platform.
Avisekhar has also worked with some big companies, such as Reliance Games in India, as well as a small-scale studio called Nautilus Mobile. He is now trying to acquire a position in the gaming industry for his own venture, Funboat Games.
I would like to mention my parents, who have supported me in every step during the journey of my career. I would not be able to write this book without their blessings. I would like to thank Mr. Pritesh Dhawle for his active support in writing the book; he is not just my partner at Funboat Games, but also an intimate friend. I'd also like to express my gratitude to Mr. Kinshuk Sunil, who supported me while writing this book at an early stage. There are many more friends and well-wishers whom I would like thank for their support.
Finally, I would like to express my gratitude toward the people who provided their valuable analysis on specific subjects; their articles and reports have helped me a lot to research more while writing this book.
Attilio Carotenuto is a senior game designer and developer with over 7 years of experience in his field. He's the owner and game director at Himeki Games, an indie studio with a focus on hardcore, premium games, currently working on An Oath to the Stars, a Japanese-style bullet hell shooter.
Attilio previously worked at companies such as Electronic Arts Playfish, King, and Space Ape Games, creating games that are played by millions of people every day.
He has previously worked with Packt Publishing as a technical reviewer for Building Levels in Unity, Volodymyr Gerasimov; Unity3D UI Essentials, Simon Jackson; and Unity 3D Game Development by Example [Video], Adam Maxwell.
You can find more about his recent projects, articles, and talks on his personal website at http://www.attiliocarotenuto.com/.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Fun is the keyword that creates the necessity for entertainment in life. There are many platforms made for entertainment, and games are one of those platforms. There are many types of games available around the world. There were times when gaming was limited to sports, board games, card games, and the like. Then, games entered the digital domain with specific gaming devices. Gradually, they have come to the mobile platform now. Android is one of the most promising platforms. The Android market is growing each day and Android gaming is growing with it.
This book is mainly aimed at game programmers. Many people consider game programming the same as any other programming job. However, my personal opinion differs—game programming is not about sitting with an open code editor and typing in a computer language, it's about creating a medium of spreading entertainment.
This book is focused on the technical part of developing a game, especially for Android. It will help a developer create games in a better way. Game programming is far more logical than technical. I have tried to clear that logic in this book with my experiences throughout my career so far.
Chapter 1, Android Game Development, will introduce you to the guidelines and rules of game development on the Android platform.
Chapter 2, Introduction to Different Android Platforms, will disclose the current variants of Android devices, such as smartphones, TVs, tablets, and smartwatches. It will elaborate all the possible difficulties while creating a game on these platforms and the possible solutions.
Chapter 3, Different Android Development Tools, will expose the different tools available to develop an Android application and how to choose suitable tools for specific purposes.
Chapter 4, Android Development Style and Standards in the Industry, will cover the current development style and standards in the game development domain. This will mainly talk about Java game coding standards and styles on the Android SDK.
Chapter 5, Understanding the Game Loop and Frame Rate, will demonstrate the creation and maintenance of game loop using the Android SDK (Java). This chapter will also cover the effects of game loop on the frame rate.
Chapter 6, Improving Performance of 2D/3D Games, will explain all the constraints of 2D and 3D game development on Android, along with the common mistakes and ways to avoid them in order to improve performance.
Chapter 7, Working with Shaders, will describe the use of shaders on the Android platform. It exposes the use of shaders through OpenGL and its scope in game development.
Chapter 8, Performance and Memory Optimization, will provide in-depth knowledge of optimizing any Android game.
Chapter 9, Testing Code and Debugging, will teach you the different ways to debug an Android game.
Chapter 10, Scope for Android in VR Games, will introduce you to virtual reality for game development on Android. This chapter describes various scopes of VR and its future in game development.
Chapter 11, Android Game Development Using C++ and OpenGL, will briefly explain game development using C++ and OpenGL.
Chapter 12, Polishing Android Games, will focus on the completion of an Android game and make it ready for release.
Chapter 13, Third-Party Integration, Monetization, and Services, will elaborate the possible integration of any third-party tools or SDKs in order to monetize the game.
It is assumed that the reader is already a game developer who has worked on the Android platform. You need to have a clear idea about Android programming using Java and C++.
The reader needs to work on various Android development platforms; most of the code works with the Android SDK. You also need to know the concept of several third-party SDKs regarding advertisements, analytics, in-app purchases, and more.
This book is ideal for any game developer with prior knowledge of developing games for Android. A good understanding of game development and basic knowledge of the Android platform application development and Java/C++ will be appreciated.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "In the Configure Project window, enter a name for the application."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
Developing games has become a very popular profession through the last decade. Previously, it was limited to PCs, consoles, and a few embedded gaming devices. Today's world is fully equipped with modern gadgets with better technology, better portability, better flexibility, and better quality. This has opened up the doors for developers to create games with better quality and fewer limitations.
Android is a modern age operating system, and is being used widely for many hardware platforms. Hence, the world of Android has become a target for game developers. The most efficient and useful targets are Android smartphones and tablets. According to surveys of the global market share for mobile OS, Android tops it with a 78-80% share in 2015. Android is now not only a mobile OS, it is being used in TVs and smart watches also. Hence, the popularity of Android is touching the sky among game developers.
This book will be helpful for those who already have a background in Android game development. Let's start with the following topics:
Let us now focus on the main topic of this book. Although game development covers many platforms and technologies, we will only focus on Android in this book.
Android is a mobile operating system based on the Linux kernel. Currently, it is being developed by Google. The OS has released many versions since 2008 to date. But after the release of Android 2.2 (Froyo) and Android 2.3 (Gingerbread), this OS caught the attention of many game developers. Android uses what is called the Dalvik Virtual Machine (DVM), which is an open source implementation of a Java Virtual Machine (JVM). There are several differences between Dalvik and a standard JVM, some subtle, some not so subtle. The DVM is also not aligned to either Java SE or Java ME, but to an Apache implementation called Apache Harmony Java. All of this makes for a slight learning curve if you happen to be transitioning from Java ME. Google introduced an alternative to DVM called Android RunTime (ART) from Android 4.4 (KitKat), and ART replaced DVM from Android 5.0 (Lollipop). ART mainly features Ahead-of-time (AOT) compilation, and an improved garbage collection process, and it provides a smaller memory footprint in order to optimize memory operations. However, most game developers use DVM to support older versions of Android devices.
Android game development started extensively when this OS was adapted by many hardware platforms. Android is mostly being used on the mobile and tablet platforms. When the mobile game industry started migrating from Symbian or Java to Android or other smart mobile OSes, Android game development started to boom.
There are a few reasons for the success of Android games:
It is always easier to use a common operating system than an embedded real-time operating system (RTOS). The user need not spend time on different hardware to learn its usability. Android is one such easy-to-use operating system.
The visual user interface is very attractive in Android, as it always runs on better hardware configuration than Symbian, Java, or an embedded OS. It enhances user experience, which is one of the reasons why it got adapted by so many organizations. As the user base of Android increased, many more game developers started targeting this platform.
From the perspective of game design, the enhanced Android features list gave flexibility to explore more in mobile games. Thus, the game design style was enhanced.
The current world has various types of hardware that run on Android. Apart from mobile phones, Android is being used on tablets, televisions, wristwatches, consoles, digital cameras, PCs, and other devices. Nowadays, game developers are targeting almost every Android platform.
Direct manipulation interface is the top feature of Android. It interacts with the user through a continuous representation of objects of interest, dynamic real-time action, and dynamic feedback. Android mainly uses a touch interface with real-time action such as swiping, dragging, tapping, and multi-touch, which are widely used in game development for Android.
Android application development is mainly based on Java (SDK) and C++ (NDK), which are the most common programming languages in the world. Hence, developing a game has become much easier.
Excellent support for multimedia took Android a step further in gaining popularity. Game developers can now use multimedia objects freely inside the game in order to increase the game quality.
Since version 2.2 (Froyo), Google has developed an integrated service called Google Play Services. It is a closed system-level API service provider, which has proved to be very useful in game development.
A large number of third-party tools available for Android development have also eased the job of game developers. Some of the tools we can mention are Android Studio, App Inventor, Corona, Delphi, Testdroid, Sample Directmedia Layer, Visual Studio, Eclipse IDE, and RubyMotions.
Android device hardware configuration has to follow a minimum configuration list, so it becomes very easy for the developers to identify the configuration. Moreover, it has to maintain a minimum standard to run applications easily.
There are plenty of sensors associated with Android devices (mostly on mobiles or tablets), which are a very good option for designing the controls of a game.
Android supports awesome connectivity through Bluetooth, Wi-Fi, GSM/CDMA/EDGE, LTE, NFC, IDEN, and the like. These help game developers to create multiplayer games easily.
Virtual reality is another field where Android is being used through Cardboard SDK. We will discuss this topic more later on.
These are the features that a game developer should keep in mind. The rest of the features are less important for game development. However, there is always a chance to explore more, and create a few specific-feature oriented games.
The main challenge in developing a game on an Android platform is to make the most use of the features in an efficient way.
The range of Android device configurations is wide. So, designing a game targeting most of them is a big challenge.
Many of the Android game developers design and build games for specific hardware configurations, like Tegra, or Snapdragon, or a particular device like Xperia Play. Nvidia's Tegra is the most commonly used chip in these situations; the THD branding often indicates that a game was built for Tegra only. Nvidia has a lot of experience working with developers on the desktop side, and has brought that expertise to mobiles. Android game developers are encouraged to make use of Tegra-specific APIs to build their games. The problem with this scenario is that most users don't have Tegra in their phones. In fact, many LTE handsets that might have otherwise had that gaming-friendly chip are being moved over to Snapdragon S4. Now, for a developer, it is very difficult to maintain performance across different graphic processors.
Android games can provide awesome user experience through their features.
Game controls can use the accelerometer or gravity sensor for a physics-based mechanism (if supported by the hardware), which is always an added advantage for real-time interactivity.
On-touch screen devices, and dynamic controls like swiping, dragging, pinching, and multi-touch, can be experienced through Android.
Android supports OpenGL for better graphic rendering, which enhances the visual quality of the game.
Miracast in Android is another feature which enables games to use multiple displays and screen sharing for a better experience.
Development of any game requires a design Android is not an exception. The design of Android games requires a lot of knowledge about the target hardware. There are thousands of varieties available for Android. Designers have to choose their target very carefully, and then design the game scope.
As previously stated, it is a challenge not only for the programmers but for the designers as well. Different Android devices have different configurations, but it is very important for a designer that the common features should be targeted.
It is a very common practice for an application developer to switch to game development and vice versa. Many do not change their style, and approach game development accordingly. Every developer of games should keep in mind that a game is not just an application.
A game can be termed an interactive entertainment system, in brief. The main objective of games is to provide fun, be it a software or physical exercise. On the other hand, the main objective of an application is to make life easier with a mechanical job. So the development approaches for these two are completely different. However, this still remains a point of discussion, as every game is an application. Any application can adapt the features of games in order to provide a better user experience.
It is difficult to differentiate between the complexities of development of a game versus an application. However, game development has an edge. Most of the application developers do not have to focus much on speed performance, whereas all game developers have to focus on speed and the frame rate of the game.
Every game is an application for sure, but every application is not a game. This statement itself conveys the message that on a single reference scale, game development has more parameters than applications, yet it has to have all the features of an application.
Application development is technology-oriented, whereas game development is fun-oriented. This increases the difficulties in game development. Fun is an emotion, there is no parameter to calculate that. So, while making games, a developer can never know what exactly the game is going to achieve in terms of fun. On the other hand, an application developer is very much certain that the application target can be achieved if all the specifications meet the requirement.
Game development very rigorously needs mathematics to work on the physics or graphics side; even AI needs a lot of mathematics for the low-level stuff. Applications are more technology driven, with limited use of graphics.
Any application that qualifies as a game must fulfill the following criteria:
The application life cycle applies to any game made on the same platform. But a game has more to the cycle, as you can see in the following diagram:
The application life cycle is simpler a game life cycle. The game cycle runs within the running phase of the application life cycle. This is typically termed the game loop. This will be discussed later in detail.
This game loop runs on game states. The application may have only one running state, but there are multiple game update states. In a typical system of game development, there are a minimum of two update states. One depends on the game loop execution, and the other depends on the time interval. The second one actually controls theframe rate.
There are noticeable differences between the performance management systems for games and applications. Performance is one of the biggest requirements in game development, whereas it is only a recommended feature for an application, as the frame rate does not affect the quality.
It is an accepted truth that games are heavier than applications on the same scale. A game runs on repetitive frames—one set of tasks runs on one frame. This increases the instruction traffic for the processor. In an application, there are generally no loops; the state of the application depends on user action. In this case, the processor gets plenty of time to execute the instruction as no instructions are being sent repetitively.
Applications which are not games have different memory management than games. In case of games, multimedia assets are the main objects, which occupy a larger portion of the heap than class objects. But in the case of applications, it is just the opposite. Applications need to load only the object they require for the state, that is, class objects.
For any game developer, memory optimization is a must. Because of the extensive use of memory, a developer cannot afford to have unused objects loaded in memory, or any memory leakage caused by mishandled memory pointers. This has a direct effect on running games. For an application, memory optimization is obviously a good practice, but most of the time it has no direct or indirect effect on running the application. However, a good programmer should always have knowledge about memory optimization.
As mentioned earlier, Android has a variety of device configurations. So, it is very important for an Android game developer to choose the target very carefully. The general approach should have these parameters:
This is basically the scale on which the game is being made. The larger the scale, the better the configuration that it'll need. This includes mainly the game size, which means the amount of memory it will consume on a device. Many Android devices are configured with very low RAM and internal memory storage. If the targeted device does not have the required configuration, the game will not run. Even if the game is fully optimized, it can fail depending on the hardware platform it is running on.
Every game requires a set of processes to be executed recursively, which requires processor speed. If a game is process-heavy, and the targeted device has a slow processor, the game will experience some horrible frame rate issue, or crash.
Every Android game developer must be aware of the requirements of memory, processor, and other constraints when choosing the target device.
Let's take the example of an Android game which requires at least 120 MB of disk space to install, 512 MB of RAM to run, and a 1.2 GHz processor speed to achieve a decent frame rate. Now consider a mobile device which matches these specifications exactly, but being a developer, one must not assume that the device will not have any other application installed or running in parallel. So, in this case, there is a fair assumption that the game will not have the required support even if the device meets its requirement. Hence, for this example game, the target device must have a higher configuration than the minimum requirement.
Now, let's take a look at the opposite scenario. Assuming the same game requirements, consider a device having 8 GB of available storage, 2 GB of RAM, and a 2 GHz multicore processor. There is no doubt that the game will run on that device with maximum performance, but the device could have supported a larger-scale game. So the resource utilization is not efficient in this scenario. This is where porting comes in. A game developer should upscale the game quality, and create a different build for those high-end configuration devices.
It is a very common practice in the industry to exclude a few devices from the targeted device list to make the game run properly. In a few cases, the game developer creates separate game builds to support most of the devices and maintain the game quality.
The target audience is the particular group for which the game is made. It is assumed that a particular set of people will have most fun from the game, or that they will play the game more than other people.
Every game design has its target audience. The set of target devices are the direct consequence of the set of target audience. For example, if the target audience is working professionals between the ages of 25 to 40, it makes no sense to create the game for an Android TV no matter what the game scale is. This is because this specific audience will mostly use mobile devices, as they have less time to sit in front of a television set. So, the list of target devices should contain mobile devices for this target audience.
We can see a lot of difference between devices in the same category. For now, let's take the example of Android mobile phones, as this is the most-used Android category. We can see a range of Android devices available in the market. Most of the Android phones are comparatively cheaper, and have fewer features. A major section of the target audience that uses such phones belongs in particular to Asia or the third world countries. So while making a game for this target audience, the developer should consider the minimum configuration target.
Feature requirement depends completely on the game design. When we talk about games on Android, the major focus is on mobile and tablet platforms. Mostly, Android games are made for these devices.
If we consider other platforms like watches, TVs, or consoles, the feature set varies. Televisions provide a bigger display with less user control, watches have limited display area and minimum configuration, consoles have better graphic quality with dedicated controls, and so on. It is very important to identify the feature list which is required to recognize the hardware devices.
There might be a scenario where an accelerometer, Bluetooth, Wi-Fi, or some other special feature is being used in a game, so the selected hardware platform must have those features. However, common mobile and tablet devices have almost the same set of features that a game developer might generally use. This feature dependency becomes very specific when Android games are made for some particular hardware platform like consoles or VR devices.
While choosing the target hardware device, every game developer must consider the scope for portability of games. The more portable a game becomes, lesser the effort required to select or choose the target hardware.
The portability of games always depends on the vision of the game developer. Porting can take two different approaches: platform porting and hardware porting. We will only focus on hardware porting here, as we have already fixed the platform to be Android.
A game developer should focus on the following points to increase the portability of a game:
A good portable game is a balanced combination of all of these preceding points. Most of the time, the target hardware is chosen first depending on the other parameters, and only then does the developer work on the portability of the 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:
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.
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.
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:
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.
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.
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.
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:
