Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
About the Author
About the Reviewers

Button press visuals

Yeah, button press visuals are great! Cocos2d is nice enough to provide a darkening of the button when we touch it, but let's add a bit more animation to our buttons to give them more of that "clicked" feeling.

Modifying the CCButton class

If we just wanted an individual button to have a specific effect, we would modify just that single button in the place where it exists. However, we want the same button effect across all buttons in our game, so we need to open CCButton.m file. The easiest way to do that is to search for CCButton in the project and click on any of the links to CCButton.m.

Here, you're going to add two functions near the top of the file: scaleButtonUp and scaleButtonDown. Both of them run actions on the button, and these actions give it a bouncy press effect found in many games:


Alternatively, you can extend/subclass CCButton and override the methods necessary to create the desired effect. This method is also slightly more stable in the case of a Cocos2d...