Let's take a look at the following steps in order to add images to the battlefield scene:
Open the
Battlefield.m
file and import theAssets
header file:#import "Assets.h"
Remove the log message and add the background image, as shown in the following code:
SPImage *background = [SPImage imageWithTexture:[Assets texture:@"water.png"]]; background.x = (Sparrow.stage.width - background.width) / 2; background.y = (Sparrow.stage.height - background.height) / 2;
Add the pirate ship, as shown in the following code:
SPImage *pirateShip = [SPImage imageWithTexture:[Assets texture:@"ship_pirate.png"]]; pirateShip.x = (Sparrow.stage.width - pirateShip.width) / 2; pirateShip.y = (Sparrow.stage.height - pirateShip.height) / 2;
Add an enemy ship using the following code:
SPImage *ship = [SPImage imageWithTexture:[Assets texture:@"ship.png"]]; ship.x = 100; ship.y = 100;
Add all children to the display tree, as shown in the following code:
[self addChild:background...