This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
manual_v1:the_scaffold_project [2013/05/25 12:08] – daniel | manual_v1:the_scaffold_project [2013/05/25 12:26] (current) – [iPad] daniel | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== The Scaffold Project ====== | ||
+ | Sparrow 1.3 brought a new scaffold project, containing a lot of built-in functionality. Things that were previously difficult to achieve are now very easy. This how-to will teach you all you need to know to get started. | ||
+ | ===== Overview ===== | ||
+ | ==== Start me up! ==== | ||
+ | |||
+ | Before we begin to modify the project, I recommend having a look at what it's capable of per default. Open it up in Xcode and start it in the simulator or on your device. It's configured as a universal app, i.e. it runs on iPhone, iPod Touch and iPad in full resolution. | ||
+ | |||
+ | When the app is started, rotate your device and see what happens: the app is rotating in all directions! | ||
+ | |||
+ | Furthermore, | ||
+ | |||
+ | There' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ==== Project contents ==== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | As you can see on the right, the project contains quite a few classes. But don't worry: you won't have to touch most of those. The **Game**-class is where your game logic starts. If you are satisfied with the defaults, you won't have to touch anything else. | ||
+ | |||
+ | Nevertheless, | ||
+ | |||
+ | * The Support-folder contains helper classes: | ||
+ | * '' | ||
+ | * The '' | ||
+ | * The Game folder contains Sparrow-based content: | ||
+ | * The '' | ||
+ | * which has its root object in the '' | ||
+ | * The '' | ||
+ | * The '' | ||
+ | * The '' | ||
+ | |||
+ | < | ||
+ | **How to enable ARC (Automatic Reference Counting)** | ||
+ | |||
+ | While the Scaffold project does not use ARC by default, it is easy to convert it to an ARC project with the help of Xcode' | ||
+ | </ | ||
+ | |||
+ | ===== Choosing a target device family ===== | ||
+ | |||
+ | An iOS app can be optimized either for iPhone/iPod Touch, for the iPad, or for both (" | ||
+ | |||
+ | * An app targeting the iPhone is always created in a resolution of 320x480 points (not pixels!). | ||
+ | * An app targeting the iPad is always created in a resolution of 768x1024 points (not pixels!). | ||
+ | * A universal app has to support both of those resolutions. | ||
+ | |||
+ | Which target device family you want to choose depends on the project. Some games only make sense on the big screen of the iPad, others will work fine on both. Make your choice as soon as possible, because it will affect the complete development process. | ||
+ | |||
+ | My recommendation is to create a universal app whenever possible. You'll reach all iOS customers that way. Yes, it's more work than the other options; but thanks to Sparrow, the additional effort is minimal. | ||
+ | |||
+ | To change the target device family, enter the target summary view of Xcode and make your choice in the " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ==== iPhone / iPod Touch ==== | ||
+ | |||
+ | There' | ||
+ | |||
+ | * The stage size of your game will be 320x480 | ||
+ | * Retina displays are supported by adding graphics with the '' | ||
+ | |||
+ | ==== iPad ==== | ||
+ | |||
+ | This requires a few minor code changes, but in the end it will work like this: | ||
+ | |||
+ | * The stage size of your game will be 768x1024 | ||
+ | * Retina displays are supported by adding graphics with the '' | ||
+ | |||
+ | To prepare the project, make the following changes in the file " | ||
+ | |||
+ | <code objc> | ||
+ | // EXCHANGE the following line: | ||
+ | [SPStage setSupportHighResolutions: | ||
+ | // with this: | ||
+ | [SPStage setSupportHighResolutions: | ||
+ | |||
+ | // DELETE the following lines: | ||
+ | BOOL isPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad; | ||
+ | int width = isPad ? 384 : 320; | ||
+ | int height = isPad ? 512 : 480; | ||
+ | |||
+ | // EXCHANGE the following line: | ||
+ | GameController *gameController = [[GameController alloc] initWithWidth: | ||
+ | |||
+ | [gameController release]; | ||
+ | // with this: | ||
+ | GameController *gameController = [[GameController alloc] init]; | ||
+ | |||
+ | [gameController release]; | ||
+ | </ | ||
+ | |||
+ | ==== Universal ==== | ||
+ | |||
+ | This configuration requires nothing special to set up. | ||
+ | |||
+ | But how does it work? The iPhone and the iPad have quite different screen sizes, after all. Here is a wiki-article describing the details: [[Universal App Development]] | ||
+ | |||
+ | To summarize: | ||
+ | |||
+ | * You have to align your objects within two different stage sizes: | ||
+ | * 320x480 for iPhone devices | ||
+ | * 384x512 for iPad devices | ||
+ | * You have to include different sets of textures for each device type: | ||
+ | * iPhone, non-retina: '' | ||
+ | * iPhone, retina: '' | ||
+ | * iPad, non-retina: '' | ||
+ | * iPad, retina: '' | ||
+ | |||
+ | ===== Handling Device Rotation ===== | ||
+ | |||
+ | The iPhone automatically rotates the user interface depending to the physical state of the device --- that was one of the most revolutionary features of the iPhone when it was first released. Here is how to do that in Sparrow-based games. | ||
+ | |||
+ | Before you jump in, keep in mind that rotating the game does not make sense in all cases. Depending on the game, it might be a lot of work to move all objects to different positions when the orientation changes. I recommend, however, to support at least both portrait or both landscape orientations. That's very easy to do. | ||
+ | |||
+ | <note important> | ||
+ | In Xcode, the supported orientations can be enabled with the corresponding buttons in the project summary. Note that the order you press those buttons is important! The first button that is activated will be the default interface orientation on startup. | ||
+ | </ | ||
+ | ==== Portrait-only ==== | ||
+ | |||
+ | To create an app that supports both portrait orientations (with the home-button at the top or bottom), choose those orientations in the target summary tab in Xcode. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | That's it! Your app will now automatically rotate to those orientations. | ||
+ | |||
+ | ==== Landscape-only ==== | ||
+ | |||
+ | To create an app that supports both landscape orientations (with the home button at the left or right side), choose those orientations in the target summary tab in Xcode. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Then open the file " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | That's it! Your app will now automatically rotate to those orientations. | ||
+ | |||
+ | ==== All orientations ==== | ||
+ | |||
+ | Per default, the Scaffold supports all orientations: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | This makes the app rotate in all directions, but of course Sparrow can't decide for itself how your objects should be distributed in which orientation. Those changes have to be done manually. | ||
+ | |||
+ | This is what the '' | ||
+ | |||
+ | <code objc> | ||
+ | [self addEventListener: | ||
+ | |||
+ | - (void)onResize: | ||
+ | { | ||
+ | NSLog(@" | ||
+ | event.isPortrait ? @" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | |||
+ | ===== Adding UIKit elements ===== | ||
+ | |||
+ | Sometimes, you want to add standard UIKit elements to your game. This is e.g. necessary when you want to display an input textfield or when you want to include Apple' | ||
+ | |||
+ | For that reason, the scaffold project creates an additional '' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | You can access this layer from the '' | ||
+ | |||
+ | - When your '' | ||
+ | - Make the '' | ||
+ | - In the corresponding event listeners, add the appropriate UIKit elements to the overlay view. | ||
+ | - If the Sparrow content needs to be informed about the results, it can call a method on the stage. | ||
+ | |||
+ | The following tutorial shows you how this is done in detail: [[Adding UIKit elements on top of Sparrow]] | ||
+ | |||
+ | |||
+ | ===== Final words ===== | ||
+ | |||
+ | These are the most important tasks you can achieve with the help of the Scaffold project. The rest of the fun lies within the '' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | //Next section: [[Extending Sparrow]]// |