Posts

Showing posts with the label Objective-C

Sending Email Landscape style in Cocos2D

Image
  [Concrete/Interesting] You know when sometimes a piece of code seems really simple, but it just won’t go right? The code just won’t behave properly. Fix one problem and another one pops up... Well, all I wanted was to use MFMailComposeViewController in my Cocos2d application. I’ve done it before so thought it would be a quick job. After many, many hours, I got it working, so to save you all the effort, here is what I did. Landscape and MFMailComposeViewController The problem was the game is in Landscape mode and it seems the mail view controller doesn’t like landscape. Works beautifully on the iPad, but the iPhone sees the world in Portrait. The standard method to launch email is to call presentModelViewController . Here’s the sort of thing that works well in Portrait: //Create the mail view controller MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject: @"The Title" ]; // Email B...

cocos2d as an Application Framework - Part 4

Image
[Concrete/Interesting] So far I think the experiment to use cocos2d as an application framework has been successful. With little effort we have a very nice look and feel, excellent menu behaviour on an iPhone and a charming looking popup dialog. Better than that, it seems relatively easy to mix UI framework into cocos2d – UI Views for example seem to behave well when added as nodes to a scene. In this last part, I’m going to try something a little more challenging. What I want to build is a sexy About box. I ;want to mix animation, a scrolling text view and a background camera view using UIImagePickerController . Containing cocos2d in a UIView To show a camera surface as the background of our cocos2d scene, we are going to have to place the cocos2d as a subview of our window’s main view. We also need to make the cocos2d scene transparent. This is a little tricky but here’s how. Look again at the selector applicationDidFinishLaunching : in the application delegate. The del...

cocos2d as an Application Framework – Part 3

Image
[Concrete/Interesting] It’s all starting to come together. We have a application and a very interesting look and feel for the menu. Now I want to really mix it up. I want to display something similar to that provided by UIAlertView , but the one from Apple just doesn’t fit the look and feel of the application under the cocos2d framework. Custom Alert in UI Kit Implementing a modal alert is relatively simple, I need create a XIB file with a single UIView : My alert view has a title, message body and two buttons, all in a nice warm look and feel: These tie back to the class definition as show in the code below: #import <UIKit/UIKit.h> #import "ColourfulButton.h" @interface ModalAlert : UIViewController { IBOutlet UILabel *alertTitle; IBOutlet UILabel *alertMessage; IBOutlet ColourfulButton *alertCancel; IBOutlet ColourfulButton *alertOk; int nResult; } @property (nonatomic, retain) UILabel *alertTitle; @property (nonatomic, retain) UILabel *ale...

cocos2d as an Application Framework – Part 2

Image
[Concrete/Interesting] In the previous blog I looked at cocos2d and showed how a simple menu could be created with very little effort. The menu is quite funky but not that exciting. cocos2d supports Sprites, so let’s build a menu with animated sprites, something like the Cover Flow you find in iTunes. Cover Flow Menu For a more exciting look and feel for the menu, I’m going to do a couple of things. First, I’m going to change the visual behaviour of the menu items – give them a sprite as well as text. Second, I’m going to modify the visual and input behaviour of the menu (the container for the menu items) to animate the menu items. For the menu items, I have to first create a class that inherits from CCMenuItem : #import <foundation/foundation.h> #import "cocos2d.h" @interface MenuItemComplete : CCMenuItem <CCRGBAProtocol> { CCLabel *title; CCNode<CCRGBAProtocol> *sprite; CCNode<CCRGBAProtocol> *spriteDisabled; float originalScale_; } ...

cocos2d as an Application Framework – Part 1

Image
[Concrete/Interesting] cocos2d is a multi-platform games engine written in C/C++. It has been ported to a number of environments including the iPhone under Objective-C. Like all developers, I dream of creating the most popular game ever. I’m probably a little too late because Pac Man day’s have come and gone. However, I believe the foundation of a games engine has application outside of the realm of games. In this first part I will be discussing the use of the cocos2d games engine as an application framework. In later articles I will expand on this to show how we can mix elements of cocos2d and the iPhone UI Framework. Basic Elements of a Games Engine Take a look at Adobe Air and even Microsoft Silverlight. Under these frameworks applications are better thought of as scenes, with layers and objects (nodes on the scene). These objects may be animation or sprites (for instance a ‘Busy’ animation) or they may be user interface elements like labels, button or menus. Layers are gr...

iPhone Offline Web Apps – the RESTful Way – Part 1 of 2

Image
[ Concrete/Very Interesting ] Whist building a web application for the iPhone, I was presented with a problem. One of my team managed to replicate the work we've been doing using Objective-C. I looked at the code – didn't like it but it worked. The problem was, it worked offline . ‘Can't have this’ I thought, so I embarked on making my application offline capable. Sounds easy – well in principle, it is. In practice, there were a few pitfalls that I thought I'd better blog about. Of course, I had a cold and had just received an H1N1 vaccination, so maybe on a good day… Anyway, here is some background and my tips to Offline Web Apps, the RESTful way. HTML5 Offline Application Cache You can find out lots of good stuff about this on the Internet. The official reference from Apple can be found here . The key is to create an cache manifest file naming all your resources - HTML files, Scripts, Style Sheets, images, and so on… You then reference the manifest file (....