Mastering AndEngine Game Development - Sample Chapter

download Mastering AndEngine Game Development - Sample Chapter

of 15

  • date post

  • Category


  • view

  • download


Embed Size (px)


Chapter No. 1 Setting Up the ProjectMove beyond basic games and explore the limits of AndEngineFor more information:

Transcript of Mastering AndEngine Game Development - Sample Chapter

  • C o m m u n i t y E x p e r i e n c e D i s t i l l e d

    Move beyond basic games and explore the limits of AndEngine

    Mastering AndEngine Game DevelopmentMaya P


    Mastering AndEngine Game Development

    AndEngine is a popular and easy-to-use game framework, best suited for Android game development. After learning the basics of creating an Android game using AndEngine, it's time to move beyond them and explore further. This book provides all the skills and tools you need in order to learn more about Android game development using AndEngine.

    You will learn how to use 3D models in a 2D scene, render a visual representation of a scene's objects, and create interactions between these objects. You will explore frame-based animations and learn to use skeletal animations.

    As the book progresses, you will be guided through exploring all the relevant aspects of rendering graphics with OpenGL ES, generating audio using OpenSL ES and OpenAL, making the best use of Android's network API, implementing anti-aliasing algorithms, shaders, dynamic lighting and much more.

    Who this book is written forThis book is aimed at developers who have gone through all the basic AndEngine tutorials and books, and are looking for something more. It's also very useful for developers with knowledge of other game engines who are looking to develop with AndEngine. Knowledge of Java, C++, and Android development are a prerequisite for getting the most out of this book.

    $ 44.99 US 28.99 UK

    Prices do not include local sales tax or VAT where applicable

    Maya Posch

    What you will learn from this book

    Extend AndEngine to use and render 3D models

    Integrate and use various physics engines with AndEngine

    Learn about advanced animations and their implementation in AndEngine

    Get to grips with lighting theory and its application for both 2D and 3D objects

    Use skeletal animation with AndEngine

    Use GLSL shaders with AndEngine for effects and anti-aliasing

    Add sounds and effects to AndEngine using both basic and 3D audio libraries

    Develop effi cient network implementations with AndEngine for multi-players

    Mastering A

    ndEngine Gam

    e Developm

    entP U B L I S H I N GP U B L I S H I N G

    community experience dist i l led

    Visit for books, eBooks, code, downloads, and PacktLib.

    Free Sam


  • In this package, you will find: The author biography

    A preview chapter from the book, Chapter 1 'Setting Up the Project'

    A synopsis of the books content

    More information on Mastering AndEngine Game Development

  • About the Author

    Maya Posch is a largely self-taught developer with a profound interest in anything related to technology and science. Having discovered programming at a young age, she proceeded to learn a variety of languages, including C++, PHP, Java, Ada, and VHDL. She has worked on mobile, desktop, and embedded applications and games. Together with a good friend, she started a software and game development company called Nyanko ( in 2006. Maya currently lives in Germany, where she works on games and other projects, and maintains a number of technology- and science-related blogs.

  • PrefaceBuilding a game for Android is easy, thanks to a multitude of game engines and tools that allow you to quickly get started. This is true for AndEngine as well. If you are reading this text, you have probably already tried your hand at, at least, a basic AndEngine game. After getting started like this, the next questions are: how to move from this game to those wonderful games you have seen elsewhere? How to make those cool animations, lighting, shadows, and other amazing effects? And how to get them with AndEngine?

    This book takes you through the many advanced topics you may encounter while making the perfect Android-based game. After explaining the theory behind each technology, it proceeds to show you how to implement it in an AndEngine-based application.

    What this book coversChapter 1, Setting Up the Project, runs through the basics of setting up an AndEngine-based application, as well as shows you how to confi gure your development environment.

    Chapter 2, Replacing 2D Sprites with 3D Models, illustrates how you can use 3D-mesh-based models with AndEngine, adding further tools to your asset development process. This chapter also provides full sample code to demonstrate how to integrate 3D models into AndEngine's rendering process.

    Chapter 3, Physics Engine Integration, demonstrates the use of the Box2D physics add-on for AndEngine and discusses 2D versus 3D physics as well as the use of other physics engines.

    Chapter 4, Frame-based Animation Sequences, discusses the various ways of implementing animation using frame-based systems. These are demonstrated using AndEngine-based examples.

  • Preface

    Chapter 5, Skeletal Animations, looks at the advanced topic of using skeleton-based animation in order to achieve highly refi ned animation without exceeding resource budgets.

    Chapter 6, Creating 3D Effects in 2D, highlights the differences and similarities between 2D and 3D scenes, and tells you how to achieve 3D effects in a 2D scene.

    Chapter 7, Static Lighting, shows the various techniques used to add lighting and shadows to a scene without making any dynamic calculations during runtime, as well as the limitations posed by this approach.

    Chapter 8, Dynamic Lighting, balances the advantages of using dynamic lighting and shadows against the disadvantages of its runtime requirements.

    Chapter 9, User Interfaces, takes a detailed look at the support available for user interfaces as they exist in AndEngine, as well as the use of native Android widgets in an AndEngine application, for example, for text input.

    Chapter 10, Shading, Aliasing, and Resolutions, dives into the complex topic of programming GLSL shaders for OpenGL ES 2.0 and better graphics hardware. This chapter also shows you how to add anti-aliasing using this and other methods. Finally, it looks at how to handle the various resolutions of the Android device that the game will eventually run on.

    Chapter 11, Adding Sounds and Effects, explores the topic of music and sound effects in a game, looking at native AndEngine APIs as well as the use of OpenSL ES and OpenAL.

    Chapter 12, Building Worlds for Our Project, focuses on the broad topic of world-building, including how to construct and load/unload scenes and the management of resources. It also looks at transitioning between different scenes and the concepts of hierarchies and limitations within a scene.

    Chapter 13, Networking and Latency, defi nes the multitude of choices out there for connecting Android devices with each other via a network as well as Bluetooth, and the implications this has on gameplay experiences. This chapter also looks at the MultiPlayer add-on for AndEngine.

    Chapter 14, Adding Custom Functionality, fi nally looks at how you can expand on the lessons learned in this book through a number of techniques to extend AndEngine's functionality without modifying a single line of its code. It also looks at implementing plugin systems in both Java and native code.

  • [ 1 ]

    Setting Up the ProjectBefore you learn the advanced techniques covered in this book, you fi rst need something to work witha project that you can use as a foundation to implement every new piece of logic and algorithm. To this end, we will use this fi rst chapter to set up the basis for the AndEngine-based application that we will build throughout the following chapters. We will also cover the basics of Android development, in both Java code and native C/C++, and see how to run and debug the resulting applications.

    In this chapter, we will cover these topics:

    Setting up a basic AndEngine project Creating scenes Running Android applications Debugging

    For this chapter, it is assumed that you have at least basic experience with developing Android applications. Experience with either Eclipse/ADT or Android Studio is useful, as is basic knowledge of coordinate systems and OpenGL.

    Project requirementsTo quickly set up an AndEngine application, we follow the general procedure of pulling the current AndEngine code from the AndEngine GitHub repository and using it as a library project dependency in our project. We will be using the GLES2-AnchorCenter branch for our project because it's the most current development branch at the time of writing this book. An additional advantage of using the AnchorCenter branch is the main change from the GLES2 branchit uses the same coordinate system as OpenGL, in the sense that the origin is in the bottom-left part of the screen. This will make our lives easier later on, as it will save us the trouble of having to convert between two different coordinate systems.

  • Setting Up the Project

    [ 2 ]

    Another difference between GLES2 and AnchorCenter is that the former positions new objects by default with the corner as the anchor point, while in the latter's case, the default anchor point is at the center of the object. We can change the anchor point wherever needed, of course, but it's good to be aware of this default behavior when we start positioning objects.

    When setting up the new Android project, we target the latest available Android SDK version (4.4.2 at the time of writing this book) and use 2.2 as the minimum SDK version, since this is what GLES2 and the related AnchorCenter branch of AndEngine require. The project we are going to create is just a general, blank Android project without any associated themes or input methods. When presented with the choice to enable any of such options in Eclipse/ADT or an