Reader small image

You're reading from  The Android Game Developer???s Handbook

Product typeBook
Published inAug 2016
Reading LevelBeginner
PublisherPackt
ISBN-139781785885860
Edition1st Edition
Languages
Right arrow
Author (1)
Avisekhar Roy
Avisekhar Roy
author image
Avisekhar Roy

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.
Read more about Avisekhar Roy

Right arrow

Chapter 6. Improving Performance of 2D/3D Games

Once upon a time, gaming on the mobile platform was limited to black-and-white pixel games, and other mediums of gaming were also heavily dependent on pixel graphics. Times have changed now. 3D games are running on handhelds with ease. However, the requirement of 2D assets has not changed yet. Even in a hardcore 3D game, 2D assets are mandatory. Few games are fully 2D.

We will discuss the performance of 2D and 3D games here with the help of the following topics:

  • 2D game development constraints

  • 3D game development constraints

  • The rendering pipeline in Android

  • Rendering through OpenGL

  • Optimizing 2D assets

  • Optimizing 3D assets

  • Common game development mistakes

  • 2D/3D performance comparison

2D game development constraints


From the perspective of 2D game development, the main constraints are as follows:

  • 2D art assets

  • 2D rendering system

  • 2D mapping

  • 2D physics

2D art assets

Art asset constraints are mainly limited to graphical or visual assets, which include images, sprites, and fonts. It is not difficult to understand that a larger asset will take more time to process and render than a smaller asset, resulting in less performance quality.

Sets of 2D art assets

It is not possible to deliver maximum display quality with a single set of assets in Android game development. This is the reason most Android game developers choose high-resolution assets as their base build. This normally performs well for high-configuration hardware platforms, but does not provide quality performance on low-configuration devices. Many developers opt for the option of porting for multiple resolution hardware platforms. This again takes time to complete the project.

Same asset set for multiple resolutions

Many times...

3D game development constraints


3D game development in Android native is very complicated. The Android framework does not support direct 3D game development platforms. 2D game development is directly supported by Android Canvas. The developer requires OpenGL support to develop 3D games for Android.

Development is supported by Android NDK, which is based on C++. We will discuss a few constraints of 3D development for Android with OpenGL support.

Android provides the OpenGL library for development. The developer needs to set up scenes, light, and camera first to start any development process.

Vertices and triangles

Vertex refers to a point in 3D space. In Android, Vector3 can be used to define the vertices. A triangle is formed by three such vertices. Any triangle can be projected onto a 2D plane. Any 3D object can be simplified to a collection of triangles surrounding its surface.

For example, a cube surface is a collection of two triangles. Hence, a cube can be formed of 12 triangles as it has...

The rendering pipeline in Android


Let's now have a look at the types of rendering pipeline in Android.

The 2D rendering pipeline

In the case of the 2D Android drawing system through Canvas, all the assets are first drawn on the canvas, and the canvas is rendered on screen. The graphic engine maps all the assets within the finite Canvas according to the given position.

Often, developers use small assets separately that cause a mapping instruction to execute for each asset. It is always recommended that you use sprite sheets to merge as many small assets as possible. A single draw call can then be applied to draw every object on the Canvas.

Now, the question is how to create the sprite and what the other consequences are. Previously, Android could not support images or sprites of a size more than 1024 x 1024 pixels. Since Android 2.3, the developer can use a 4096 x 4096 sprite. However, using such sprites can cause permanent memory occupancy during the scopes of all the small assets. Many low...

Optimizing 2D assets


Any digital game cannot be made without 2D art assets. There must be 2D assets in some form inside the game. So, as far as game component optimization is concerned, every 2D asset should also be optimized. Optimization of 2D assets means these three main things.

Size optimization

Each asset frame should only contain the effective pixels to be used in games. Unnecessary pixels increase the asset size and memory use during runtime.

Data optimization

Not all images require full data information for pixels. A significant amount of data might be stored in each pixel, depending on the image format. For example, full screen opaque images should never contain transparency data. Similarly, depending on the color set, images must be formatted in 8-bit, 16-bit, or 24-bit format.

Image optimization tools can be used to perform such optimizations.

Process optimization

The larger the amount of data compressed during optimization, the more time it takes to decompress it and load it to memory...

Optimizing 3D assets


A 3D art asset has two parts to be optimized. A 2D texture part is to be optimized in the same 2D optimization style. The only thing the developer needs to consider is after optimization, the shader should have the same effect on the structure.

The rest of the 3D asset optimization entirely depends on the number of vertices and the model polygon.

Limiting the polygon count

It is very obvious that a large number of polygons used to create a mesh can create more details. However, we all know that Android is a mobile OS, and it always has hardware limitations.

The developer should count the number of polygons used in the mesh and the total number of polygons rendered on the screen in a single draw cycle. There is always a limitation depending on the hardware configuration.

So, limiting the polygon and vertex count per mesh is always an advantage in order to achieve a certain frame rate or performance.

Model optimization

Models are created with more than one mesh. Using a separate...

Common game development mistakes


It is not always possible to look into each and every performance aspect at every development stage. It is a very common practice to use assets and write code in a temporary mode and use it in the final game.

This affects the overall performance and future maintenance procedure. Here are few of the most common mistakes made during game development.

Use of non-optimized images

An artist creates art assets, and the developer directly integrates those into the game for the debug build. However, most of the time, those assets are never optimized, even for the release candidate.

This is the reason there may be plenty of high-bit images where the asset contains limited information. Alpha information may be found in opaque images.

Use of full utility third-party libraries

The modern day development style does not require each and every development module to be written from scratch. Most of the developers use a predefined third-party library for common utility mechanisms...

2D/3D performance comparison


Android game development in 2D and 3D is different. It is a fact that 3D game processing is heavier than 2D games. However, the game scale is always the deciding factor.

Different look and feel

3D look and feel is way different than 2D. The use of a particle system in 3D games is very common to provide visual effects. In the case of 2D games, sprite animation and other transformations are used to show such effects.

Another difference between 2D and 3D look and feel is dynamic light and shadow. Dynamic light is always a factor for greater visual quality. Nowadays, most 3D games use dynamic lighting, which has a significant effect on game performance. In the case of 2D games, light management is done through assets. So, there is no extra processing in 2D games for light and shadow.

In 2D games, the game screen is rendered on a Canvas. There is only one fixed point of view. So, the concept of camera is limited to a fixed camera. However, in 3D games, it is a different...

Summary


The scope of 3D games is increasing day by day with more quality and performance. However, this requires hardware support for the running Android platform. Old devices are not obsolete yet.

It becomes a serious problem when the same application runs on various devices. This becomes a challenge for developers to run the same application across devices.

There are many technical differences between 2D and 3D games in terms of rendering, processing, and assets. The developer should always use an optimized approach to create assets and write code. One more way of gaining performance is to port the games for different hardware systems for both 2D and 3D games.

We can see a revolutionary upgrade in hardware platforms since the last decade. Accordingly, the nature of games has also changed. However, the scope of 2D games is still there with a large set of possibilities.

There are many frameworks and engines available for developing 2D and 3D games. Support for multiple operating systems has...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Android Game Developer???s Handbook
Published in: Aug 2016Publisher: PacktISBN-13: 9781785885860
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Avisekhar Roy

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.
Read more about Avisekhar Roy