Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

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 code:

    uint redColor = SP_COLOR(200, 0, 0);
    SPQuad *quadMaxHitpoints = [SPQuad quadWithWidth:hitpointsBorder.width - 2.0f height:hitpointsHeight - 2.0f color:redColor];
  6. We set the background for the hit points box to have a one point margin, which...