To display the hit points for each ship, we just need to follow these steps:
Open our game's project file if it's not already open.
Switch to the
Ship.h
file.Add an instance variable called
_quadHitpoints
, which is a pointer toSPQuad
, as shown in the following line of code:SPQuad *_quadHitpoints;
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];
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];
We set the background for the hit points box to have a one point margin, which...