1. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Game Development with AndEngine GLES2
Daniela da Cruz
Computação Móvel
Licenciatura em Engenharia de Jogos Digitais
Instituto Politécnico do Cávado e do Ave
October 28, 2013
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
2. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Introduction
Basic Elements
Camera
Engine
Scene
Entity
Texture TextureRegion
Creating the rst scene with AndEngine
Handling Scene touches
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
3. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Introduction
AndEngine is a free open source OpenGL Android game engine,
developed by Nicolas Gramlich.
AndEngine is currently available in two avors: GLES1 and GLES2.
GLES2, as you might guess, supports OpenGL ES 2.0.
https://github.com/nicolasgramlich
http://www.matim-dev.com/
Latest version:
Tutorials:
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
4. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Introduction
AndEngine Advantages:
It has a complete 2-D scene graph, with a very easy-to-use
API.
It works great with the Android activity lifecycle.
It has a number of extensions that can be added as plugins.
It has multi-touch support.
It's free and open-source.
AndEngine Disadvantages:
The API is undocumented.
Sometimes slower in comparison to other engines.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
5. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Basic Elements
To create a scene we need 3 basic elements:
Camera
Engine
Scene
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
6. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Camera
Camera
Since all is based in a game scene we need to setup a camera:
Camera(pX, pY, pWidth, pHeight);
pX and pY are the coordinates for the origin of the camera
pWidth and pHeight are the dimensions, in pixels, of the
camera
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
7. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Engine
Engine
In the engine we dene which camera will be used on the scene:
EngineOptions(pFullscreen, pScreenOrientation,
pResolutionPolicy(pWidth, pHeight), pCamera)
pFullscreen determines whether the game will be play full
screen or not
pScreenOrientation, here we can choose between
LANDSCAPE and PORTRAIT
pResolutionPolicy is the ratio of our Engine (same values as in
Camera)
pCamera is the camera object
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
8. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Scene
Scene
The Scene class is the root container for all objects to be drawn on
the screen.
A Scene has a specic amount of Layers, which themselves can
contain a (xed or dynamic) amount of Entities.
There are subclasses, like the CameraScene/HUD/MenuScene that
are drawing themselves to the same position of the Scene no
matter where the camera is positioned to.
HUD (heads-up display) usage for example for score (it has
to be all the time in the same position, follow camera
changes).
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
9. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Entity
Entity
An
Entitiy is an object that can be drawn, like Sprites, Rectangles,
Text or Lines.
An Entity has a position/rotation/scale/color/etc.
Sprite - entity with texture
TiledSprite - entity with tiled texture, you may switch between
tiles.
AnimatedSprite - extension of the TiledSprite, you may
animate tiles in specied intervals.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
10. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Texture TextureRegion
Texture TextureRegion
A Texture is a 'image' in the memory of the graphics chip.
A TextureRegion denes a rectangle on the Texture. A
TextureRegion is used by Sprites to let the system know what part
of the big Texture the Sprite is showing.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
11. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Creating the rst scene with AndEngine
The rst le created by the project is an
Activity.
And the rst thing to do in our project is to change the class that
this Activity extends.
Instead of extending the Activity class, we want to make it extend a
class called SimpleBaseGameActivity.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
12. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Creating the rst scene with AndEngine
The SimpleBaseActivity class provides additional callbacks and
contains the code to make AndEngine work with the Activity life
cycle.
Each callback that it provides is used for a specic purpose. As
soon as you extend this class, we will have to override three
functions.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
13. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Extending SimpleBaseGameActivity
onCreateEngineOptions this function is where you create
an instance of the engine. Every activity that the game uses
will have its own instance of the engine that will run within the
activity lifecycle.
onCreateResources this is the function where we load all
the resources that the activity requires into the the VRAM.
onCreateScene this function is called after the above two
callbacks are executed. This is where we create the scene for
our game and use all the textures that we previously loaded
into memory.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
14. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Extending SimpleBaseGameActivity
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
15. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Creating a Sprite
When creating a Sprite object, we pass four parameters:
xCoordinate: Denes the X-position of the sprite.
yCoordinate: Denes the Y-position of the sprite.
TextureRegion: Denes what part of the texture the sprite will
use to draw itself.
VertexBuerObjectManager: Think of a vertex buer as an
array holding the coordinates of a texture. These coordinates
are passed to the OpenGL ES pipeline and ultimately dene
what will be drawn. A VertexBuerObjectManager holds all
the vertices of all the textures that need to be drawn on the
scene.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
16. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Attaching a Sprite to a Scene
To attach a sprite, to a dierent entity, for example to the Scene,
we have to simply call
attachChild
method:
anyEntity.attachChild(yourSprite);
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
17. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Handling Scene touches
Lets say we want to execute a certain action, every time the player
touches the screen.
We have to implement
IOnSceneTouchListener
interface.
Add unimplemented method.
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
18. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Handling Scene touches
The methods that identify if an event occurred or not are:
isActionDown(), isActionMove(), isActionUp().
Now all you have to do is to register this touch listener in a certain
scene:
scene.setOnSceneTouchListener(this);
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave
19. Introduction
Basic Elements
Creating the rst scene with AndEngine
Handling Scene touches
Handling Entity touches
The problem of this approach is that it will handle every event that
occurs in the whole scene.
If we want to handle touch events of specic entities, we will need
to implement the method
onAreaTouch()
(the parameters are the
event and its coordinates).
Game Development with AndEngine GLES2
Computação MóvelLicenciatura em Engenharia de Jogos DigitaisInstituto Politécnico do Cávado e do Ave