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 – adding images to the battlefield scene


Let's take a look at the following steps in order to add images to the battlefield scene:

  1. Open the Battlefield.m file and import the Assets header file:

    #import "Assets.h"
  2. 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;
  3. 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;
  4. Add an enemy ship using the following code:

    SPImage *ship = [SPImage imageWithTexture:[Assets texture:@"ship.png"]];
    ship.x = 100;
    ship.y = 100;
  5. Add all children to the display tree, as shown in the following code:

    [self addChild:background...