This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:creating_a_sparrow_project_from_scratch_xcode_3 [2013/03/05 10:19] – external edit 127.0.0.1 | tutorials:creating_a_sparrow_project_from_scratch_xcode_3 [2014/07/03 10:35] (current) – [How to create a Sparrow project from scratch (Xcode 3)] daniel | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== How to create a Sparrow project from scratch (Xcode 3) ====== | ||
+ | Sometimes, you want to use Sparrow without having the option to use the app scaffold or the Xcode template. This can happen e.g. when you want to integrate Sparrow into an existing project. This is a topic that pops up regularly in the forum. | ||
+ | |||
+ | That's why I wrote this tutorial. Don't worry, it's not difficult --- most of the steps have to be followed in any non-trivial iPhone application. However, there are some things that many of us are not accustomed to, like using Xcode' | ||
+ | |||
+ | This tutorial starts from scratch. When you follow it step by step, the outcome will be a project just like the app scaffold that's part of Sparrow. Good luck! | ||
+ | |||
+ | <note warning> | ||
+ | This article is about Sparrow 1.x!\\ | ||
+ | For Sparrow 2.x, please visit [[Creating a Sparrow Project from Scratch]]. | ||
+ | </ | ||
+ | |||
+ | ==== 1. Set up the Sparrow project reference ==== | ||
+ | |||
+ | |||
+ | - Create a new " | ||
+ | - Open your project in Xcode | ||
+ | - In the " | ||
+ | - When the "Add to Project" | ||
+ | * Copy items (...): no | ||
+ | * Reference Type: Relative to '' | ||
+ | * Text Encoding: '' | ||
+ | * Recursively create groups for any added folders: yes | ||
+ | |||
+ | ==== 2. Configure the Library Dependencies, | ||
+ | |||
+ | - Click on " | ||
+ | - Set "User Header Search Paths" to: '' | ||
+ | - Still in the Build-settings, | ||
+ | - Click on " | ||
+ | - In the same Window, under " | ||
+ | - Finally, click and drag " | ||
+ | |||
+ | ==== 3. Create the base Source Classes ==== | ||
+ | |||
+ | //Create Game.h:// | ||
+ | |||
+ | <code objc> | ||
+ | #import < | ||
+ | #import " | ||
+ | |||
+ | @interface Game : SPStage | ||
+ | |||
+ | @end | ||
+ | </ | ||
+ | |||
+ | //Create Game.m:// | ||
+ | |||
+ | <code objc> | ||
+ | #import " | ||
+ | |||
+ | @implementation Game | ||
+ | |||
+ | - (id)initWithWidth: | ||
+ | { | ||
+ | if (self = [super initWithWidth: | ||
+ | { | ||
+ | // this is where the code of your game will start. | ||
+ | // in this sample, we add just a simple quad to see | ||
+ | // if it works. | ||
+ | |||
+ | SPQuad *quad = [SPQuad quadWithWidth: | ||
+ | quad.color = 0xff0000; | ||
+ | quad.x = 50; | ||
+ | quad.y = 50; | ||
+ | [self addChild: | ||
+ | } | ||
+ | return self; | ||
+ | } | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | //Modify ProjectAppDelegate.h:// | ||
+ | |||
+ | <code objc> | ||
+ | #import < | ||
+ | #import " | ||
+ | |||
+ | @interface ProjectAppDelegate : NSObject & | ||
+ | { | ||
+ | UIWindow *window; | ||
+ | SPView *sparrowView; | ||
+ | } | ||
+ | |||
+ | @property (nonatomic, retain) IBOutlet UIWindow *window; | ||
+ | @property (nonatomic, retain) IBOutlet SPView *sparrowView; | ||
+ | |||
+ | @end | ||
+ | </ | ||
+ | |||
+ | //Modify ProjectAppDelegate.m:// | ||
+ | |||
+ | <code objc> | ||
+ | #import " | ||
+ | #import " | ||
+ | |||
+ | @implementation ProjectAppDelegate | ||
+ | |||
+ | @synthesize window; | ||
+ | @synthesize sparrowView; | ||
+ | |||
+ | - (void)applicationDidFinishLaunching: | ||
+ | { | ||
+ | SP_CREATE_POOL(pool); | ||
+ | | ||
+ | [SPStage setSupportHighResolutions: | ||
+ | [SPAudioEngine start]; | ||
+ | | ||
+ | Game *game = [[Game alloc] init]; | ||
+ | sparrowView.stage = game; | ||
+ | [game release]; | ||
+ | | ||
+ | [window makeKeyAndVisible]; | ||
+ | [sparrowView start]; | ||
+ | | ||
+ | SP_RELEASE_POOL(pool); | ||
+ | } | ||
+ | |||
+ | - (void)applicationWillResignActive: | ||
+ | { | ||
+ | [sparrowView stop]; | ||
+ | } | ||
+ | |||
+ | - (void)applicationDidBecomeActive: | ||
+ | { | ||
+ | [sparrowView start]; | ||
+ | } | ||
+ | |||
+ | - (void)dealloc | ||
+ | { | ||
+ | [sparrowView release]; | ||
+ | [window release]; | ||
+ | [super dealloc]; | ||
+ | } | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | ==== 4. Create a Sparrow View ==== | ||
+ | |||
+ | - Open " | ||
+ | - Drag a " | ||
+ | - In the properties of the View, set the class manually to " | ||
+ | - If you need support for multitouch, activate it in the leftmost tab | ||
+ | - Make a connection to the '' | ||
+ | - Save the file and quit interface builder. | ||
+ | |||
+ | ==== 5. Phew! Done! (Hopefully) ==== | ||
+ | |||
+ | If everything works, you should see a window with a red square. Congratulations! |