My SimpleButton Cocos2D class

Cocos2D for iPhone sadly does not have a class for a button that lets you customize it with different text, text color, and background color. After some research, I decided the easiest way to do this on my own would be to create a button from a blank sprite, set a color for that sprite, and attach the text to that sprite. So I created a class that did just that. This weekend, I upgraded the class a bit to support a border and simple drop-shadow (really just a slightly displaced block of color). It’s still acting a little weird, but I put some hours into it, so I’ll post the code here for those who may want to see what I did.

SimpleButton.h, SimpleButton.m

I use the class by creating the button and then messing with the padding, borderWidth, and shadowOffset properties. Here’s a screenshot of the current Dungeonism zone menu, which uses the class:

Dungeonism Menu

Tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>