O'Reilly logo

Sparrow iOS Game Framework Beginner's Guide by Johannes Stein

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

Time for action – putting buttons on the screen

To add our first buttons, follow these steps:

  1. Open the Battlefield.h file.
  2. Add one instance variable for each button. We will use the SPButton type, as shown in the following code:
    SPButton *_buttonPause;
    SPButton *_buttonResume;
  3. Switch to the Battlefield.m file.
  4. Construct the instances for our two instance variables, as shown in the following code:
    _buttonPause = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"button_pause"]];
    _buttonResume = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"button_play"]];
  5. Set the position of both the pause and resume buttons to the top-right corner of the screen using the following code:
    _buttonPause.x = Sparrow.stage.width ...

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