Skip to main content

Posts

Showing posts from 2010

Cocos2d Customize Labels and Fonts

cocos2d supports both TTF (True Type Fonts) labels, and texture atlas labels. (Please note that from cocos2d Version .7+ on, the label is added to it's layer via addChild: and not add: e.g. [self addChild:myLabel];) Pros and Cons of TTF labels: ( CCLabel ) * + All the pros of TTF fonts: any size, kerning support, etc. * + Easy to use. No need to use an external editor. * - The creation/update is very slow since a new texture will be created Pros and Cons of texture atlas labels: ( CCLabelAtlas, CCBitmapFontAtlas ) * + The creation / update is very fast, since they don't create a new texture. * + Fonts can be customized (shadows, gradients, blur, etc) * - Depends on external editors: AngelCode / Hiero editor, GIMP / Photoshop Creating labels: Simple way The easiest way to create a label is by using the CCLabel object. Example: CCLabel *label = [CCLabel labelWithString:@"Hello World" f...

Implement Push Notification in iPhone Game or Application

One of the widely anticipated features of the new iPhone OS 3.0 is push notifications which allow messages to be sent directly to an individual device relevant to the application that has been installed. Apple have demoed this as useful for news alerts, or IM notifications however it fits in perfectly with the nature of our server monitoring service, Server Density. As part of the product, we have an iPhone application that includes push notifications as an alerting option so you can be notified via push direct to your iPhone when one of your server alerts have been triggered. This is useful since our app can then be launched to instantly see the details of the server that has caused the alert. Apple provides detailed code documentation for the iPhone OS code that is needed to implement and handle the alerts on the device but only provides a higher level guide for the provider server side. As a provider, you need to communicate with the Apple Push Notification Service (APNS) to s...

Game Engine and Games Framework List

Freeware engines These engines are available for free use, but without the source code being available under an open source license. Many of these engines are commercial products which have a free edition available for them: * Adventure Game Studio — Mainly used to develop third-person pre-rendered adventure games, this engine is one of the most popular for developing amateur adventure games. * Cocos2d— A 2d game engine for making iphone games. * DikuMUD and derivatives — MUD engines * dim3 — Freeware 3D javascript engine for the Mac (although finished games are cross platform). * DX Studio — A freeware 3D game engine with complete tools for 3D video game development. Upgrading to paid licenses would unlock extra features. * Game Maker Lite — Object-oriented game development software with a scripting language as well as a drag-and-drop interface. * LPMud and derivatives (including MudOS and FluffOS) — MUD engines * MUSH — MU* engine * M.U...

iPhone Map Kit - Tutorial and Code

I tried looking for some online resources that could be of some help but did not find any. I was not able to find any good tutorial that explains how can an address be shown on a map with the application. Therefore, I decided to write one and here it is. Hope it will be of some help. Lets create a simple application which displays the address entered by the user on the map within the application. We’ll call it MapApp. 1. First, create a Window based application and name the project as MapApp. 2. Add the MapKit framework to the project. (Control + Click Frameworks folder -> Add -> Existing Frameworks) 3. Create a new view controller class and call it MapViewController. Add a text field, button and map view to it. #import #import @interface MapViewController : UIViewController { IBOutlet UITextField *addressField; IBOutlet UIButton *goButton; IBOutlet MKMapView *mapView; } @end 4. Now create a xib file named M...

Touch Detection in cocos2d iphone example

First you need to set self.isTouchEnabled = YES; in init method of your layer. The three approaches are: 1.Dumb input management. This isn't dumb in the sense of stupid, but instead is dumb in the sense of a dumb missile that will keep flying straight until it hits something. A more precise description would be ignorant of global state. While usually not usable as-is in non-demo applications, this approach underpins the other two approaches, and is thus important. Simply subclass CocosNode and implement any or all of these three methods (you don't have to define them in the interface, they're already defined by a superclass). -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; oint location = [touch locationInView: [touch view]]; [self doWhateverYouWantToDo]; [self doItWithATouch:touch]; } -(void)touchesMoved:(NSSet *)touches withEvent:(U...

Display UITextField in Cocos2d Game

I create the UITextField like normal: txtName = [[UITextField alloc] initWithFrame: CGRectMake(160, 240, 200, 32)]; I add it to the subview like so: [[[CCDirector sharedDirector] openGLView] addSubview: txtName]; The problem I'm having is that, when I change the orientation to PortraitUpsideDown with this command: [[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationPortraitUpsideDown]; the UITextField and the keyboard don't change with the new orientation. When I click on the text box, the keyboard appears upside down and on the top of the screen. I know I can change the rotation of the UITextField using CGAffineTransformMakeRotation, but how do I make the keyboard appear upright and at the bottom of the screen when in PortraitUpsideDown orientation? When I detect an orientation change, in addition to setting the Director's device orientation like so: [[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationPortraitUpsideDown]; I...

Mac App Store Coming Soon - Port your cocs2d game for Mac

Apple to announce that in 90 days Mac App Store will be ready. The Mac App Store will be similar to the App Store, but instead of distributing iOS applications, it will distribute Mac applications. This is big news for cocos2d users, since cocos2d already supports Mac!! The guidelines and other requirements for the Mac App Store are online: * Mac App Store Review Guidelines * App Store Resource Center So, download the latest cocos2d version, and start porting your cocos2d game for Mac!

Cocos2d Game Development Performance Tips

Cocos2d for iPhone is a wonderful open source framework that makes it easy to draw 2D graphics with OpenGL ES. It allows to you unlock the power of the graphics hardware in iPhone OS devices, without having to deal with all the details of working with GL. Having said that, using Cocos2d is a great way to get your feet wet with GL programming. I’d never done any OpenGL stuff before, but I found I picked up quite a bit as I went along. It handles most of the hard stuff, but it’s very easy to subclass and handle drawing yourself as you become more experienced. When I started working on the bizarre experiment that eventually became Space Harvest, I initially used Core Animation. This is great, up to a point, but I found I soon hit a performance wall - Core Animation wasn’t flexible enough to handle the types of things I wanted to do, and doesn’t really give you a lot of control over what’s happening under the hood. Once I switched to Cocos2d, I found that a) it was a lot easier to get ...

How To Avoid Having Your App Rejected for Core Functionality Issues and Crashing

The two most common reasons for application rejection are issues with core functionality and crashing. Core functionality encompasses the belief that customers rightfully expect all the features described in the marketing text and release notes to work as described, and likewise that all the buttons and menu items within the application will be fully functional (i.e., no grayed out buttons or notifications that a feature will be implemented later). Before you submit your app for approval, make sure that every aspect of your application is fully functional and that the marketing text and release notes correspond to the end user experience. Also, make sure you thoroughly test your application on iPhone and iPod touch in addition to the iPhone Simulator. A large percentage of applications are rejected due to various types of crashes, including crashes on launch, which would have been found and dealt with if they'd been tested on an actual device. Don't skip that step in the develo...

Tutorials for iPad Development

While the iPad and iPhone share iOS as their operating system there are many aspects of development for the iPad that are considerably different and should be understood by developers looking to create the best possible iPad apps. On this page I have decided to list tutorials specifically created for the iPad along with other resources such as user interface design tips, and graphical resources such as UI prototyping tools and vector kits. You can expect this page to update with new tutorials and resources so be sure to bookmark it. Newer resources appear towards the top of the listing. 1. Rapid Prototyping of iPad apps using Keynote – a great guide along with many interactive elements for prototyping (key here being interactive) using Keynote. 2. How To Port An App To the iPad – Covers how to convert your app to handle the iPad screen sizes, specifically autosizing and orientation, and when to use iPad elements. 3. Custom Input View Tutorial – A tutorial on how to create grea...

Tutorials for iPad Development

While the iPad and iPhone share iOS as their operating system there are many aspects of development for the iPad that are considerably different and should be understood by developers looking to create the best possible iPad apps. On this page I have decided to list tutorials specifically created for the iPad along with other resources such as user interface design tips, and graphical resources such as UI prototyping tools and vector kits. You can expect this page to update with new tutorials and resources so be sure to bookmark it. Newer resources appear towards the top of the listing. 1. Rapid Prototyping of iPad apps using Keynote – a great guide along with many interactive elements for prototyping (key here being interactive) using Keynote. 2. How To Port An App To the iPad – Covers how to convert your app to handle the iPad screen sizes, specifically autosizing and orientation, and when to use iPad elements. 3. Custom Input View Tutorial – A tutorial on how to create grea...

Open Source Game Engine Comparison for iPhone

There are several open source game engines to choose from, and many cropping up all the time. On this page I have only listed those that I know have been used in games already available on the iPhone or iPad. I have chosen not to list those for which there are no apps available in the app store. Choosing Your Open Source iPhone Game Engine Sparrow Framework The Sparrow Framework is a very lightweight 2D game engine created in Objective-C. In a very short amount of time I was able to understand the framework, and I find it to be very intuitive. If you’d like to take a look at some actual coding with the Sparrow Framework be sure to check out the Beginners iPhone Action Game Programming Tutorial. While I have not done much Flash game programming the developers state that the game engine was created with Flash game developers in mind. The game framework includes all the necessary features you’d require for creating a basic 2D game such as easy animation, and a sound engine. Cocos2D IPh...

Integrating AdMob with Cocos2D-iPhone Applications

This post provides the code needed to display AdMob ads within Cocos2D using a UIViewController. Much of the initial content is still the same, but the code reflects the slight changes required to support the use of a UIViewController. The updated code was tested on a 3G running IOS 4 and Cocos2D 0.99.3. AdMob is a mobile advertising network that serves ads to be displayed on mobile devices. Ads can be served via native applications or within a browser and are not limited to just smart phones. AdMob offers plenty of metrics to track the quantity of served ads, geographic region, which cellphone operator, and device type. This tutorial will provide the guidance needed to include AdMob served ads within your Cocos2D-iPhone application. This example is based upon v.82 of the Cocos2D-iPhone framework. Your first step is to register with AdMob to get a publisher ID and input information regarding your application. Registration and eventual access to the SDK is free. Once registered ...

OpenFeint Integration with cocos2d

If you want to integrate your cocos2d game with openfeint leaderboard then follow following steps. Openfeint is used for live leaderboard for games, achievement, forum, live chat and many community features as well. It will decrease developers efforts to maintain highscores and achievement etc. OpenFeint is a service that enables your iPhone/iPod Touch application the ability to provide online score tracking. The service is free and can easily be incorporated into your applications. This tutorial will cover the integration of OpenFeint 2.4.3 with the Cocos2D-iPhone framework. Before getting started, it is assumed that you already have familiarity with: * Objective-C * XCode * Cocos2D-iPhone framework The expectation is that you already have a working Cocos2D based application to which you’d like to enable leaderboard functionality. If you’re new to Cocos2D-iPhone, then you should visit http://www.cocos2d-iphone.org to review the available documentation and download the...