This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
manual:the_barebone_project [2013/05/31 08:18] – [Application Delegate] daniel | manual:the_barebone_project [2013/05/31 08:18] (current) – [Game Class] daniel | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== The Barebone Project ====== | ||
+ | |||
+ | Sparrow contains two projects that can be the basis for your games. The " | ||
+ | |||
+ | When you start the Barebone application, | ||
+ | |||
+ | Now have a look at the source code of the project. | ||
+ | |||
+ | ===== Application Delegate ===== | ||
+ | |||
+ | This is the startup class of any iOS project. Normally, you'd initialize your UIKit objects in this class. Since we're creating a Sparrow game here, we set up Sparrow instead --- which turns out to be quite simple. | ||
+ | |||
+ | <code objc AppDelegate.h> | ||
+ | @interface AppDelegate : NSObject < | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | <code objc AppDelegate.m> | ||
+ | @implementation AppDelegate | ||
+ | { | ||
+ | SPViewController *_viewController; | ||
+ | UIWindow *_window; | ||
+ | } | ||
+ | |||
+ | - (BOOL)application: | ||
+ | didFinishLaunchingWithOptions: | ||
+ | { | ||
+ | // create a full-screen window | ||
+ | CGRect screenBounds = [UIScreen mainScreen].bounds; | ||
+ | _window = [[UIWindow alloc] initWithFrame: | ||
+ | | ||
+ | // start up Sparrow | ||
+ | _viewController = [[SPViewController alloc] init]; | ||
+ | [_viewController startWithRoot: | ||
+ | | ||
+ | // activate the window | ||
+ | [_window setRootViewController: | ||
+ | [_window makeKeyAndVisible]; | ||
+ | | ||
+ | return YES; | ||
+ | } | ||
+ | |||
+ | @end | ||
+ | </ | ||
+ | |||
+ | As you can see, most of the code is actually responsible for standard UIKit setup. To start up Sparrow, we create an instance of the " | ||
+ | |||
+ | If you want to make some adjustments on Sparrow properties, this is the right place to do so. Just access the respective properties of the view controller --- here are a few of the most common ones: | ||
+ | |||
+ | <code objc> | ||
+ | _viewController.showStats = YES; | ||
+ | _viewController.multitouchEnabled = YES; | ||
+ | _viewController.preferredFramesPerSecond = 60; | ||
+ | </ | ||
+ | |||
+ | You may have noticed that we're passing a class called " | ||
+ | |||
+ | ===== Game Class ===== | ||
+ | |||
+ | This is the starting point of your game. Everything you do in Sparrow will be somehow initiated from this class. | ||
+ | |||
+ | <code objc Game.h> | ||
+ | @interface Game : SPSprite | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | <code objc Game.m> | ||
+ | @implementation Game | ||
+ | |||
+ | - (id)init | ||
+ | { | ||
+ | if ((self = [super init])) | ||
+ | { | ||
+ | // this is where the code of your game will start. | ||
+ | // in this sample, we add just a simple quad | ||
+ | |||
+ | SPQuad *quad = [SPQuad quadWithWidth: | ||
+ | quad.color = 0xff0000; // 0xRRGGBB -> this is red | ||
+ | quad.x = 50; | ||
+ | quad.y = 50; | ||
+ | [self addChild: | ||
+ | } | ||
+ | return self; | ||
+ | } | ||
+ | |||
+ | @end | ||
+ | </ | ||
+ | |||
+ | As you can see, the Game class inherits from '' | ||
+ | |||
+ | In the sample, the content is just a simple '' | ||
+ | |||
+ | Hit the " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ----- | ||
+ | |||
+ | //Next section: [[Display Objects]]// | ||