O'Reilly logo

Cocos2D Game Development Essentials by Ben Trengrove

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding buttons to your scene

Buttons are a requirement for almost any app. You will have to use them constantly in your game development. Cocos2d v3 makes this very simple with the introduction of the new class, CCButton. This is a great improvement over version 2 for those familiar with it. Making buttons is now as easy as making any other node. It is even better as they support block-based callbacks or target/selector calls that gives you the flexibility to work with buttons however you like.

Buttons have three states:

  • Default
  • Selected
  • Disabled

If you open up IntroScene.m in your Xcode project, you will see an example of a button being created:

 // Helloworld scene button CCButton *helloWorldButton = [CCButton buttonWithTitle:@"[ Start ]" fontName:@"Verdana-Bold" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required