Archive for the 'source code' Category

A SpaceManager Game

This article is going to build upon the basics described in the previous SpaceManager article written some time ago which can be found here: http://www.cocos2d-iphone.org/archives/677

About the Author:

My name is Rob, I’m one of the guys working under the mobile bros. LLC title. We’ve released a few games in the recent years, all using SpaceManager, including: Pachingo, Trundle, and Kill Timmy. I am personally interested in physics myself and always looking for new ways to incorporate them in our games.

Goals

Today’s goal is to design a basic game using Cocos2d, Chipmunk, and SpaceManager. I believe the best lessons are those learned from example, so for this article I’ll walk you through building a small example of a game and show off some of the features of SpaceManager. Some of the things we’ll demonstrate here are:

* Save and Load entire game state
* Explosions in Chipmunk
* Creating a debug-layer
* Using impulses
* Retina Support

So what type of game should we do… perhaps one where we slingshot grenades at structures hoping to kill some kind of ninja animal inside? Sounds like a plan, so lets dive right in. This tutorial will use Cocos2d 0.99.5 and SpaceManager 0.0.6. I HIGHLY recommend you download the accompanying source code for this article so you can follow along; this will have everything you need and you can skip the setup steps. Source is found here:

Download the Source-Code: GrenadeGame.zip

Edit: Updated source location

Continue reading ‘A SpaceManager Game’

cocos2d migrated to git/github

The official cocos2d source code repository was migrated from SVN to Git. Also, the source code is hosted in GitHub.

The master branch is the stable branch, while the develop branch is the unstable branch.

How to download the develop branch ?

git clone http://github.com/cocos2d/cocos2d-iphone.git develop

New to git ?

For further info, please see this thread: http://www.cocos2d-iphone.org/forum/topic/5295

Notifications in OpenGL (Like OpenFeint but without lag)

I (manucorporat) have developed a notification system for cocos2D. It’s very useful when your game uses OpenFeint or another social network.

OpenFeint has his own notification system, and probably you wonder, Why am I going to use this new system?

The answer is easy. The new system is designed in OpenGL and the performance is higher.

No more lag, when a friend connect!!!

In addition, It has a lot of advantages.

  • You can customize the notification design. (Friendly to the rest of the interface)
  • High Performance, because it uses OpenGl instead of UIKit.
  • Personalized animations (in and out).
  • cocos2d based. (Easy integration)
  • Personalized notification position (Top and bottom)
  • Easy way to play sounds when a notification is showed.
  • Easy implementation with OpenFeint.
  • Callback when it’s pressed. (Like Openfeint)

AbstractWar 2.0 uses this system.

Are you interested?

Integrating this feature in your game/app is very easy:
In CCDirector.m::mainloop
You must add [[CCNotifications sharedManager] visit]; after [runningScene_ visit];
And #import "CCNotifications.h"

/* draw the scene */
 
[runningScene_ visit];
[[CCNotifications sharedManager] visit]; //<<<<<<<<
if( displayFPS )
[self showFPS];

Ok, now you can push a notification if you write this code:

[[CCNotifications sharedManager] addNotificationTitle:@"Game Name:" message:@"Running in 1.4 version" image:nil tag:0 animate:YES];

Openfeint integration:

Open (ProyectName)AppDelegate.m
It must implement <OpenFeintDelegate, OFNotificationDelegate, CCNotificationsDelegate> protocols.

- (void) applicationDidFinishLaunching:(UIApplication *)application {
 
//Openfeint init
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation,
@"Name", OpenFeintSettingShortDisplayName,
window, OpenFeintSettingPresentationWindow,
nil
];
 
OFDelegatesContainer* delegates = [OFDelegatesContainer containerWithOpenFeintDelegate:self andChallengeDelegate:nil andNotificationDelegate:self];
 
[OpenFeint initializeWithProductKey:@"yourkey"
andSecret:@"yourpassword"
andDisplayName:@"your proyect name"
andSettings:settings
andDelegates:delegates];
 
//CCNotifications delegate
[[CCNotifications sharedManager] setDelegate:self];
}
 
#pragma mark OpenFeint Delegate methods
 
- (BOOL) isOpenFeintNotificationAllowed:(OFNotificationData*)notificationData{
 
return NO;
 
}
 
- (void)handleDisallowedNotification:(OFNotificationData*)notificationData{
 
[[CCNotifications sharedManager] addNotificationTitle:@"Openfeint:" message:[notificationData notificationText] image:@"openfeintLogo.png" tag:1 animate:YES];
 
}

Delegate methods:

- (void) notificationChangeState:(char)state tag:(int)tag {
if(state == kCCNotificationStateShowing){
//Play sound
}
}
- (BOOL) touched:(int)tag{
//Example
/*
if(tag==kTagOpenfeint) {
	[OpenFeint launchDashboard];
}
*/
}

Customize:
You can customize the notification design in CCNotificationDefaultDesign class.

  • The position:
[[CCNotifications sharedManager] setPosition:kCCNotificationPositionBottom]; //kCCNotificationPositionTop
  • Animations:

Animation (In):

[[CCNotifications sharedManager] setAnimationIn:kCCNotificationAnimationMovement time:0.4f];

Animation (Out):

[[CCNotifications sharedManager] setAnimationOut:kCCNotificationAnimationMovement time:0.4f];

Both:

[[CCNotifications sharedManager] setAnimation:kCCNotificationAnimationMovement time:0.4f];
  • Time:
[[CCNotifications sharedManager] setShowingTime:3.2f];

Other usages:

  • Show app version.
  • Music now playing
  • New DLC content. (In-app purchase)

Conclusion: If you have got a game with cocos2D and it uses OpenFeint, I recommend that you implement this feature. It’s also a plus to get Openfeint Gold.

Forum discussion
Check here to download the code.

For further updates, follow me on Twitter or keep an eye on my blog.




Social Widgets powered by AB-WebLog.com.