-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Mastering Cocos2d Cross-Platform Game Development
By :
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.
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...
Change the font size
Change margin width
Change background colour