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.
[[CCNotifications sharedManager] setPosition:kCCNotificationPositionBottom]; //kCCNotificationPositionTop
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];
[[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.
Recent Comments