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 – placing a health bar on top of each ship

To display the hit points for each ship, we just need to follow these steps:

  1. Open our game's project file if it's not already open.
  2. Switch to the Ship.h file.
  3. Add an instance variable called _quadHitpoints, which is a pointer to SPQuad, as shown in the following line of code:
    SPQuad *_quadHitpoints;
  4. Switch to the Ship.m file. Just after where we create the cannonball images in the initializer, we add a quad which should be the border for our hit point representation, as shown in the following code:
    float hitpointsHeight = 5.0f;
    SPQuad *hitpointsBorder = [SPQuad quadWithWidth:clipNorth.width height:hitpointsHeight color:SP_BLACK];
  5. We add the background for the hit points box, as shown in the following ...

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