The Barebone Project

Sparrow contains 2 projects that can be the basis for your games. The “Barebone” project is one of it. It provides just the minimal code you need to create a Sparrow powered application.

Use this project for your first tests with the Sparrow Framework. It's super lightweight and does not contain any content that might confuse beginners.

When you start the Barebone application, you will see a red rectangle on the screen. This rectangle was rendered with Sparrow — if you can see it, everything was set up correctly.

Now have a look at the source code of the project. For now, the only important class is “Game”. It is the starting point of your game. All necessary setup-stuff (creating the window, connecting Sparrow to UIKit, etc.) was already prepared for you.

(If that sounds too easy, you can create the project from scratch, too!)


@interface Game : SPStage


@implementation Game
- (id)initWithWidth:(float)width height:(float)height
    if (self = [super initWithWidth:width height:height])
        // this is where the code of your game will start.
        // in this sample, we add just a simple quad
        SPQuad *quad = [SPQuad quadWithWidth:100 height:100];
        quad.color = 0xff0000; // 0xRRGGBB -> this is red
        quad.x = 50;
        quad.y = 50;
        [self addChild:quad];
    return self;

As you can see, the Game class inherits from SPStage. The stage is the root display object of your game. Everything that is somehow connected to your stage will be rendered. To create a game, you populate the stage with your content.

In the sample, the content is just a simple SPQuad (a red rectangle). It has a color (red), a size (100×100) and a position (50, 50). And it is a child of the stage. It has to be, otherwise it would not be rendered. This is a part of the “display tree” architecture of Sparrow, into which we will dive in the following section.

How to enable ARC (Automatic Reference Counting)

While the Barebone project does not use ARC by default, it is easy to convert it to an ARC project with the help of Xcode's refactoring tool. Find it under “Edit — Refactor — Convert to Objective-C ARC”. Beware that Sparrow itself should not be converted to ARC; it's enough to convert your project.

Next section: Display Objects

  manual_v1/the_barebone_project.txt · Last modified: 2013/03/05 10:19 (external edit)
Powered by DokuWiki