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.

8 Responses to “Notifications in OpenGL (Like OpenFeint but without lag)”


  • This is awesome.

    I was going to implement OpenFeint in my current game. I will certainly have a play with this.

    Thanks for sharing

  • This is golden. Definitely something I will be using in my game :)

  • This looks great! Thanks a bunch for putting this up! Next time I use OF, I will definitely take a look at this!

  • Wow! That’s great! This is exactly what I was looking for!

  • nice, i will use it!

  • This doesn’t seem to work any more :(

    First you need to change CCColorLayer to CCLayerColor – that’s fine.

    But there seem to be some more serious problems with squareColors.

  • update color goes like this

    - (void) updateColor
    {
    //Gradient code
    ccColor3B colorFinal = ccc3(0, 50, 100);

    squareColors_[0].r = color_.r;
    squareColors_[1].g = color_.g;
    squareColors_[2].b = color_.b;
    squareColors_[3].a = opacity_;

    squareColors_[4].r = color_.r;
    squareColors_[5].g= color_.g;
    squareColors_[6].b = color_.b;
    squareColors_[7].a = opacity_;

    squareColors_[8].r = colorFinal.r;
    squareColors_[9].g = colorFinal.g;
    squareColors_[10].b = colorFinal.b;
    squareColors_[11].a = opacity_;

    squareColors_[12].r = colorFinal.r;
    squareColors_[13].g = colorFinal.g;
    squareColors_[14].b = colorFinal.b;
    squareColors_[15].a = opacity_;

    }

Leave a Reply




Social Widgets powered by AB-WebLog.com.