SparrowLogoThis is a two-part article.  Be sure to read the second part “Migration of HelloWorld iOS game from Sparrow 1.4 to Sparrow 2.0 – Part II“.

Sparrow is a pretty awesome Free and Open Source game engine for iOS. If you are gearing up to develop a game or just want to start learning game development as a hobby then Sparrow is a great place to start. It is a pure Objective-C library that has kept performance at its core.

While looking for game development resources I discovered that Sparrow 2.0 had recently been released. There are some great new features in the new release.

  • All new architecture, based on OpenGL ES 2 and iOS 5.
  • Using pure ARC throughout the framework
  • Up to two times the performance of the old version
  • Block-based event listeners and tween callbacks
  • Asynchronous texture loading (from local file or remote server)
  • Powerful new Tween functionality
  • Super simple UIKit Integration
  • Skewing of Display Objects
  • Auto-scaling of text
  • Much faster Bitmap-Font rendering
  • Statistics display showing current FPS and number of draw calls

After reading the manuals and perusing the tutorials it was time to see it all put together in a good example. The problem – no complete Sparrow 2.0 examples.

The first Sparrow 1.4 example that caught my eye was HelloWorld. This is, after all, where a developer always starts. HelloWorld is an iOS game written by Andreas Wålm [github] using ARC, CocoaPods, Universal and Sparrow 1.4. The rest of this post outlines the changes made to the HelloWorld Sparrow 1.4 example.

Starting with the Barebones Project

Being unsure of the changes required to migrate HelloWorld to the Sparrow Framework 2.0 I started off with the Sparrow provided “Barebone” project.  This project supplied as part of the framework download provides what is needed to get started quickly.

I decided to start a root repo for this project as opposed to a fork of walm/helloworld-game repo because my approach was going to change to many files.  With the repo and barebones project in place I copied all the needed resources from the original project into the new project folder and added them to the Xcode project:

            • header files (.h)
            • method files (.m)
            • media files
            • icons

Implement the new initialization process

The startup class of an iOS project is the Application Delegate.    In the didFinishLaunchingWithOptions: we will want to initialize Sparrow.  This is a much simpler process than before and is facilitated by SPViewController being a subclass of GLKViewController.   Let’s get this implemented by starting with the changes to AppDelegate.h

Changed to

Here the ViewController, a subclass of UIViewController, switches to an SPViewController.  Simple way to start. Now we will implement the new controller.

In the original code we init the GameController and add it to the SPView as the root stage.  Then the ViewController is initialized using the SPView.    The GameController creates the Game instance and the game will start.

Changed to

You can quickly see that the Sparrow setup process is simple.  Instantiate the SPViewController.  This class will create the view and set the stage automatically.  It also creates the root object instance of the game by passing the desired root class to the startWithRoot: method.  The root object is the Game (SPSprite) class.

This eliminates the use of ViewController (the subclass of UIViewController), GameController and SPView.  Without an SPView you might ask how to set multitouchEnabled and preferredFramesPerSecond.  These properties are now accessible from SPViewController.  The stage and root object of the game are also now available from the Sparrow class which provides static convenience methods to certain properties of the current SPViewController as well as the currentController itself.

Subscribe to BehindTheCode.Net and continue reading “Migration of HelloWorld iOS game from Sparrow 1.4 to Sparrow 2.0 – Part II“.

Fork the source code from github

Find out more about the release of Sparrow Framework 2.0