Thông tin tài liệu
www.it-ebooks.info
AndEngine for Android
Game Development
Cookbook
Over 70 highly effective recipes with real-world examples
to get to grips with the powerful capabilities of AndEngine
and GLES 2
Jayme Schroeder
Brian Broyles
BIRMINGHAM - MUMBAI
www.it-ebooks.info
AndEngine for Android Game Development
Cookbook
Copyright © 2013 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 authors, 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: January 2013
Production Reference: 1070113
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-898-7
www.packtpub.com
Cover Image by Jayme Schroeder (jayme.schroeder@gmail.com)
www.it-ebooks.info
Credits
Authors
Jayme Schroeder
Brian Broyles
Reviewers
Mateusz Mysliwiec
Sergio Viudes Carbonell
Jafar Abdulrasoul [Jimmar]
Acquisition Editor
Kartikey Pandey
Lead Technical Editor
Sweny M. Sukumaran
Technical Editors
Sharvari Baet
Dominic Pereira
Project Coordinator
Priya Sharma
Proofreader
Kevin McGowan
Indexer
Rekha Nair
Graphics
Aditi Gajjar
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
www.it-ebooks.info
About the Authors
Jayme Schroeder was introduced to computers at a very young age. By 11, he had started
creating modications and level packs for his favorite game. By age 16, he had found his true
passion in game development and network programming in C++ and OpenGL. In early 2011,
Jayme had received an Android smartphone and immediately fell in love with the development
experience. Since then, he has been researching and developing for the Android platform on a
daily basis.
There are many people I would like to thank for the opportunity to write this
book and also thank those who helped me out every step of the way.
First and foremost, I would like to thank Packt Publishing for the acceptance
of AndEngine for Android Game Development Cookbook and Amber D'souza
for rst approaching me with the opportunity to write this book. I would also
like to thank Kartikey Pandey, Michelle Quadros, Sweny Sukumaran, Priya
Sharma from Packt Publishing who all played a large part in making the
writing process much easier than anticipated and comfortable for me. I would
also like to thank Dominic Pereira and Sharvari Baet for the effort they've put
in throughout the production stage and the suggestions they've made.
I would like to thank Nicolas Gramlich for creating AndEngine. Not only has
he created an amazing engine for novice and advanced developers alike,
but he's created a great community for Android developers to both learn
and strengthen their development skills relating to game development.
I would like to also thank my co-author, Brian Broyles, for his contributions
and commitment
to the book. It's been an honor to share the experience with him.
Finally, I would like to thank all of my family and friends who showed their
support and provided feedback during this experience. More specically, I
would like to thank Kent and Judy Schroeder; my parents, Shannon, Hollie,
Taylor, and Brittanie; my brothers and sisters and my girlfriend, Krystal
Guevremont. Of my friends, I would like to specically thank Leo Wandersleb
and Jordi Puigdellívol, with whom I've spent many days discussing the ner
details of AndEngine which greatly helped to improve my knowledge.
www.it-ebooks.info
Brian Broyles is a freelance programmer and 2D/3D graphic designer with over
12 years of experience. Before entering the mobile development industry in 2010 as the
lead programmer of IFL Game Studio, he designed advanced articial intelligence systems
and graphical effects for interactive PC applications. In addition to his vast programming and
design experience, he is also a commercial pilot, instrument ight instructor, and advanced
instrument ground instructor.
I'd like to thank my amazing, beautiful wife, Bethany, for her support and
enthusiasm as well as my family for encouraging me in all of my endeavors.
www.it-ebooks.info
About the Reviewers
Mateusz Mysliwiec was born 1993 in Tarnow, Poland, graduating from high school
in 2012. He currently lives in England. During his last year of high school, he decided that
he would like to study Software Engineering or a different subject connected with math,
programming, and engineering. He is also an independent game developer. In his free time,
he develops professional mobile games focusing especially on the Android platform. His goal
is to permanently impact the global mobile gaming industry in the near future. He is active in
a variety of projects, including open source. His passions away from game development are
sports and recreation such as football, skydiving, and jogging. His family and friends are the
important aspects of his life.
Sergio Viudes is a 30 years old software developer from Elche (Spain). He works
developing commercial web apps, and develops video games for Android in his free time.
He likes to play video games since childhood. He started playing with his brother's Spectrum
when he was 5 years old. When he bought his rst PC (well, his parents did), he was 14 years
old, and started learning computer programming, computer drawing, and music composing
(using the famous "FastTracker 2"). When he nished high school, he studied Computer
Science at the University of Alicante.
His interest in mobile devices started with his rst smart phone, ten years ago (2002), when
he bought the rst Symbian device from Nokia, the Nokia 7650. He really liked the idea that
he could develop software that could run everywhere. So, along with his studies and his job,
Sergio started creating simple mobile apps for his phone. About two years ago he decided to
create his rst video game for mobile devices. He really enjoys developing for mobile devices,
he likes to compose music, he likes to draw, and, of course, he likes to play video games.
So he decided to put all his hobbies together and develop his rst video game for his favorite
mobile platform—Android.
So far Sergio has released 3 games and he continues developing apps and games for Android
as a hobby. He wishes that someday it will be his job, not just a hobby.
www.it-ebooks.info
Jafar Abdulrasoul—a graduate from the Kuwait University—is a Computer Engineer and an
Android game enthusiast who wrote a couple of excellent tutorials on his blog about creating
games using AndEngine. He is known online by the name Jimmar.
My gratitude goes to my mother who tries to support me in everything I do,
so thank you mama!
www.it-ebooks.info
www.PacktPub.com
Support les, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support les and downloads related to
your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
les 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
service@packtpub.com 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.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
f Fully searchable across every book published by Packt
f Copy and paste, print and bookmark content
f On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: AndEngine Game Structure 7
Introduction 7
Know the life cycle 8
Choosing our engine type 14
Selecting a resolution policy 17
Creating object factories 18
Creating the game manager 20
Introducing sounds and music 23
Working with different types of textures 27
Applying texture options 34
Using AndEngine font resources 39
Creating the resource manager 42
Saving and loading game data 45
Chapter 2: Working with Entities 51
Introduction 51
Understanding AndEngine entities 52
Applying primitives to a layer 58
Bringing a scene to life with sprites 62
Applying text to a layer 69
Using relative rotation 74
Overriding the onManagedUpdate method 77
Using modiers and entity modiers 81
Working with particle systems 93
www.it-ebooks.info
[...]... stylish and fun games by both independent and professional developers alike, and has even been used in some of the most successful games on the market to date However, it takes more than just using a specific framework to achieve success AndEngine for Android Game Development Cookbook provides many informative walkthroughs relating to the most important aspects of AndEngine at a general game- programming... code, GIMP for image drawing/editing, and Inkscape for SVG drawing/editing Please feel free to use alternatives to these products if you are more comfortable with them Additionally, this book assumes the reader has obtained the required libraries, including AndEngine and its various extensions prior to working with the recipes Who this book is for AndEngine for Android Game Development Cookbook is... http://downloads.packtpub.com/sites/default/files/ downloads/8987OS_AppB_Final.pdf 2 www.it-ebooks.info Preface What you need for this book AndEngine for Android Game Development Cookbook is useful for the majority of AndEngine developers Starting with the first few chapters, the reader will begin to work with the basics of AndEngine, and even intermediate developers will find useful tips throughout these chapters As the reader... platform Creating a physics-based rope bridge Game level classes Input classes Layer classes Manager classes Menu classes 307 313 316 323 327 336 347 348 350 351 Index 355 iii www.it-ebooks.info Table of Contents iv www.it-ebooks.info Preface AndEngine is an excellent, full-featured, free, and open source 2D framework for the Android platform It is one of few 2D frameworks for the Android platform... Creating the game manager The game manager is an important part of most games A game manager is a class that should contain data relating to gameplay; including, but not limited to keeping track of score, credits/currency, player health, and other general gameplay information In this topic, we're going to take a look at a game manager class to gain an understanding of how they work into our game structure... blocks of AndEngine and the game structure in order to create precise, organized, and expandable projects www.it-ebooks.info AndEngine Game Structure In this chapter, we're going to go over a few of the most necessary components of AndEngine and general game programming We're going to take a look at some classes that will aid us in quickly and efficiently creating a foundation for all sorts of games Additionally,... copied/pasted into our LayoutGameActivity class after step one has been completed: @Override protected int getLayoutID() { return R.layout.main; } @Override protected int getRenderSurfaceViewID() { return R.id.gameSurfaceView; } 13 www.it-ebooks.info AndEngine Game Structure The SimpleBaseGameActivity and SimpleLayoutGameActivity classes The SimpleBaseGameActivity and the SimpleLayoutGameActivity classes,... cycle of an AndEngine game to placing sprites on the scene and moving them around, all the way through to creating destructible objects and raycasting techniques Even more importantly, this book is entirely based on AndEngine' s latest and most efficient Anchor-Center branch What this book covers Chapter 1, AndEngine Game Structure, covers the important aspects of game development with AndEngine regarding... www.it-ebooks.info AndEngine Game Structure 3 Create a reset method that will revert all data back to their initial values: // Resetting the game simply means we must revert back to initial values public void resetGame(){ this.mCurrentScore = GameManager.INITIAL_SCORE; this.mBirdCount = GameManager.INITIAL_BIRD_COUNT; this.mEnemyCount = GameManager.INITIAL_ENEMY_COUNT; } How it works… Depending on the type of game. .. pOnPopulateSceneCallback.onPopulateSceneFinished(); } 9 www.it-ebooks.info AndEngine Game Structure How it works… The code found in this recipe's class is the foundation for any AndEngine game We've set up a main activity class which serves as the entry point into our application The activity contains the four main methods included in AndEngine' s activity life cycle that we are responsible for, beginning with creating the EngineOptions . and foremost, I would like to thank Packt Publishing for the acceptance
of AndEngine for Android Game Development Cookbook and Amber D'souza
for. http://downloads.packtpub.com/sites/default/files/
downloads/8987OS_AppB_Final.pdf.
www.it-ebooks.info
Preface
3
What you need for this book
AndEngine for Android Game Development Cookbook is useful for the majority of AndEngine
developers. Starting
Ngày đăng: 07/03/2014, 02:20
Xem thêm: AndEngine for Android Game Development Cookbook docx, AndEngine for Android Game Development Cookbook docx