Adding buttons to the menu
In AndEngine, we can create touch-responsive buttons out of any Entity
object or Entity
object subtype. However, AndEngine includes a class called ButtonSprite
whose texture representation depends on whether the Entity
object is pressed or unpressed. In this recipe, we're going to take advantage of AndEngine's ButtonSprite
class and override its onAreaTouched()
method in order to add touch-responsive buttons to our menu and/or game's Scene
object. Additionally, the code within this recipe regarding touch events can be applied to any other Entity
object within our game.
Getting ready…
This recipe requires basic knowledge of the Sprite
object in AndEngine. Please read through the entire recipe, Working with different types of textures in Chapter 1, AndEngine Game Structure, specifically the section regarding tiled texture regions. Next, visit the recipe, Bringing a scene to life with sprites in Chapter 2, Working with Entities.
Once the recipes regarding textures and...