is there a place the final version of this is all online?
Notifications in OpenGL (Like Openfeint)
(55 posts) (23 voices)-
Posted 3 years ago #
-
bump - anyone?
Posted 3 years ago # -
I have published in github the last version of CCNotifications:
http://github.com/manucorporat/CCNotificationsThere are an important new method:
You can send notifications from any thread.
- (void) addSafelyWithTitle:(NSString*)title message:(NSString*)message image:(NSString*)image tag:(int)tag animate:(BOOL)animate;Posted 2 years ago # -
New version of CCNotifications.
- More stable
- You can use several notification designs.
- addSafelyWithTitle fixed.I recommend update to the last version and use this method to show notifications:
- (void) addSafelyWithTitle:(NSString*)title message:(NSString*)message image:(NSString*)image tag:(int)tag animate:(BOOL)animate;You can download it here:
http://github.com/manucorporat/CCNotificationsPosted 2 years ago # -
Thanks for this!
I'll be using this in my next game 'Push Panic' :)
Posted 2 years ago # -
Thanks, the new version works fine BTW :)
Nice Job!
Posted 2 years ago # -
Well,congrats, works great and seems useful
Just one problem, possibly something silly, as I'm new with this, but I get it to work showing my own notiifications and everything, and I also have OpenFeint implemented and working, I just can get the little notiffications from Openfeint to show using your notification system!!(Maybe some code just seems odd, but it's 3am here so everythings possible..too many imports I know, need to clean it)
In my appDelegate.h
#import <UIKit/UIKit.h> #import "CCNotifications.h" #import "OpenFeint.h" #import "OFNotificationDelegate.h" #import "OFDelegate.h" #import "WindTennisOFDelegate.h" @class WindTennisOFDelegate; @interface WindTennisAppDelegate : NSObject <UIApplicationDelegate, OFNotificationDelegate,CCNotificationsDelegate> { UIWindow *window; WindTennisOFDelegate *ofDelegate; } @property (nonatomic, retain) UIWindow *window; @endappDelegate.mm
#import "WindTennisAppDelegate.h" #import "cocos2d.h" #import "MainMenuScene.h" #import "Cocos2DController.h" #import "ScoreScene.h" #import "OpenFeint.h" #import "WindTennisOFDelegate.h" #import "OFDelegate.h" - (void) applicationDidFinishLaunching:(UIApplication*)application { //Openfeint init NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation, [NSNumber numberWithBool:YES], OpenFeintSettingEnablePushNotifications, nil ]; ofDelegate = [WindTennisOFDelegate new]; OFDelegatesContainer *delegates = [OFDelegatesContainer containerWithOpenFeintDelegate:ofDelegate]; [OpenFeint initializeWithProductKey:@"YOUR_PRODUCT_KEY" andSecret:@"YOUR_APP_SECRET" andDisplayName:@"WindTennis" andSettings:settings andDelegates:delegates]; // Init CCNotifications (very easy) [[CCNotifications sharedManager] setDelegate:self]; [[CCDirector sharedDirector] runWithScene: [MainMenuScene node]]; ] #pragma mark OpenFeint Delegate methods - (BOOL) isOpenFeintNotificationAllowed:(OFNotificationData*)notificationData{ NSLog(@"intento 1"); return NO; } - (void)handleDisallowedNotification:(OFNotificationData*)notificationData{ NSLog(@"intento2"); [[CCNotifications sharedManager] addSafelyWithTitle:@"Openfeint:" message:[notificationData notificationText] image:@"openfeintlogo.png" tag:1 animate:YES]; NSLog(@"intento 3"); }After seeing It didn´t work I added the Nslogs to see if they are called any time an OFNotifications shows, but the aren´t
Are those two delegates methods supose to be there, on the AppDelegate?also, my AppOFDelegate
.h
#import "OpenFeintDelegate.h" @interface WindTennisOFDelegate : NSObject < OpenFeintDelegate > - (void)dashboardWillAppear; - (void)dashboardDidAppear; - (void)dashboardWillDisappear; - (void)dashboardDidDisappear; - (void)userLoggedIn:(NSString*)userId; - (BOOL)showCustomOpenFeintApprovalScreen; @end.m
#import "cocos2d.h" #import "WindTennisOFDelegate.h" #import "OpenFeint+UserOptions.h" #import "CCNotifications.h" @implementation WindTennisOFDelegate - (void)dashboardWillAppear { [[CCDirector sharedDirector] pause]; } - (void)dashboardDidAppear { [[CCDirector sharedDirector] stopAnimation]; } - (void)dashboardWillDisappear { } - (void)dashboardDidDisappear { [[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation]; } - (void)userLoggedIn:(NSString*)userId { OFLog(@"New user logged in! Hello %@", [OpenFeint lastLoggedInUserName]); } - (BOOL)showCustomOpenFeintApprovalScreen { return NO; } @endPosted 2 years ago # -
You should write OFDelegate correctly
OFDelegatesContainer* delegates = [OFDelegatesContainer containerWithOpenFeintDelegate:ofDelegate andChallengeDelegate:nil andNotificationDelegate:ofDelegate];AppOFDelegate.h
@interface WindTennisOFDelegate : NSObject < OpenFeintDelegate, OFNotificationDelegate > @endAppOFDelegate.m
#import "OFNotification.h" #import "cocos2d.h" #import "WindTennisOFDelegate.h" #import "OpenFeint+UserOptions.h" #import "CCNotifications.h" @implementation WindTennisOFDelegate - (void)dashboardWillAppear { [[CCDirector sharedDirector] pause]; } - (void)dashboardDidAppear { [[CCDirector sharedDirector] stopAnimation]; } - (void)dashboardWillDisappear { } - (void)dashboardDidDisappear { [[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation]; } - (void)userLoggedIn:(NSString*)userId { OFLog(@"New user logged in! Hello %@", [OpenFeint lastLoggedInUserName]); } - (BOOL)showCustomOpenFeintApprovalScreen { return NO; } - (BOOL) isOpenFeintNotificationAllowed:(OFNotificationData*)notificationData { return NO; } - (void)handleDisallowedNotification:(OFNotificationData*)notificationData{ [[CCNotifications sharedManager] addSafelyWithTitle:@"Openfeint:" message:[notificationData notificationText] image:nil tag:-1 animate:YES]; } @endPosted 2 years ago # -
thanks for answering, but I don't get it to work yet..
http://dl.dropbox.com/u/313914/OFNotificationsOGL.zip
the are the files where the problem should be..
WindTennisAppDlegate.h/.mm
WindTennisOFDelegate.h/.mm
MainMenuScene.h/.mm
MainMenuLayer.h/.mm
It just a test app, Your notifications work great by themselves, and OpenFeint too.
The AppDelegate loads the MainMenuSCene, wich loads the MainMenu Layer.Posted 2 years ago # -
First you must write this code in CCDirector:mainloop
/* draw the scene */ [runningScene_ visit]; [[CCNotifications sharedManager] visit]; //<<< HERE if( displayFPS ) [self showFPS];WindTennisAppDelegate.mm
// // WindTennisAppDelegate.m // WindTennis // // Created by Alberto Sendra on 12/07/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "WindTennisAppDelegate.h" #import "cocos2d.h" #import "MainMenuScene.h" #import "Cocos2DController.h" #import "ScoreScene.h" #import "OpenFeint.h" #import "WindTennisOFDelegate.h" #import "OFDelegate.h" @implementation WindTennisAppDelegate @synthesize window; - (void) applicationDidFinishLaunching:(UIApplication*)application { // CC_DIRECTOR_INIT() // // 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer // 2. EAGLView multiple touches: disabled // 3. creates a UIWindow, and assign it to the "window" var (it must already be declared) // 4. Parents EAGLView to the newly created window // 5. Creates Display Link Director // 5a. If it fails, it will use an NSTimer director // 6. It will try to run at 60 FPS // 7. Display FPS: NO // 8. Device orientation: Portrait // 9. Connects the director to the EAGLView // CC_DIRECTOR_INIT(); // Obtain the shared director in order to... CCDirector *director = [CCDirector sharedDirector]; // Sets landscape mode [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; // Turn on display FPS [director setDisplayFPS:YES]; // Turn on multiple touches EAGLView *view = [director openGLView]; [view setMultipleTouchEnabled:YES]; // Default texture format for PNG/BMP/TIFF/JPEG/GIF images // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 // You can change anytime. [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888]; //Openfeint init NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation, [NSNumber numberWithBool:YES], OpenFeintSettingEnablePushNotifications, nil ]; OFDelegatesContainer* delegates = [OFDelegatesContainer containerWithOpenFeintDelegate:ofDelegate andChallengeDelegate:nil andNotificationDelegate:self]; [OpenFeint initializeWithProductKey:@"blablanla" andSecret:@"blablabla" andDisplayName:@"WindTennis" andSettings:settings andDelegates:delegates]; // Init CCNotifications (very easy) [[CCNotifications sharedManager] setDelegate:self]; [[CCDirector sharedDirector] runWithScene: [MainMenuScene node]]; } #pragma mark CCNotifications delegate methods (optional) - (void) notificationChangeState:(char)state tag:(int)tag { switch (state) { case kCCNotificationStateHide: NSLog(@"Notification hidden"); //Play sound break; case kCCNotificationStateShowing: NSLog(@"Showing notification"); //Play sound break; case kCCNotificationStateAnimationIn: NSLog(@"Animation-In, began"); //Play sound break; case kCCNotificationStateAnimationOut: NSLog(@"Animation-Out, began"); //Play sound break; default: break; } } #pragma mark OpenFeint methods - (BOOL) isOpenFeintNotificationAllowed:(OFNotificationData*)notificationData { return NO; } - (void)handleDisallowedNotification:(OFNotificationData*)notificationData { [[CCNotifications sharedManager] addSafelyWithTitle:@"Openfeint:" message:[notificationData notificationText] image:@"openfeintlogo.png" tag:-1 animate:YES]; } #pragma mark App state methods - (void)applicationWillResignActive:(UIApplication *)application { [[CCDirector sharedDirector] pause]; [OpenFeint applicationWillResignActive]; } - (void)applicationDidBecomeActive:(UIApplication *)application { [[CCDirector sharedDirector] resume]; [OpenFeint applicationDidBecomeActive]; } - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { [[CCDirector sharedDirector] purgeCachedData]; } - (void)applicationWillTerminate:(UIApplication *)application { [[CCDirector sharedDirector] end]; [[NSUserDefaults standardUserDefaults] synchronize]; } - (void)applicationSignificantTimeChange:(UIApplication *)application { [[CCDirector sharedDirector] setNextDeltaTimeZero:YES]; } - (void)dealloc { [[CCDirector sharedDirector] release]; [window release]; [super dealloc]; } @endWindTennisOFDelegate.h
#import "cocos2d.h" #import "WindTennisOFDelegate.h" #import "OpenFeint+UserOptions.h" #import "CCNotifications.h" @interface WindTennisOFDelegate : NSObject < OpenFeintDelegate > - (vid)dashboardWillAppear; - (vid)dashboardDidAppear; - (vid)dashboardWillDisappear; - (void)dashboardDidDisappear; - (vid)userLoggedIn:(NSString*)userId; - (BOOL)showCustomOpenFeintApprovalScreen; @endWindTennisOFDelegate.mm
#import "OFNotification.h" #import "cocos2d.h" #import "WindTennisOFDelegate.h" #import "OpenFeint+UserOptions.h" #import "CCNotifications.h" @implementation WindTennisOFDelegate - (void)dashboardWillAppear { [[CCDirector sharedDirector] pause]; } - (void)dashboardDidAppear { [[CCDirector sharedDirector] stopAnimation]; } - (void)dashboardWillDisappear { } - (void)dashboardDidDisappear { [[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation]; } - (void)userLoggedIn:(NSString*)userId { OFLog(@"New user logged in! Hello %@", [OpenFeint lastLoggedInUserName]); } - (BOOL)showCustomOpenFeintApprovalScreen { return NO; } @endPosted 2 years ago # -
I had everything like that already, so, nothing, still doesn't work..
@manucorporat, nada que no, ya lo tenia así y no me va. La linea esa en CCDirector:mainloop ya la tenia añadida, si puedo lanzar notificaciones con tu sistema en cualquier momento, me va perfectamente, al igual que me va OpenFeint perfectamente, con Achievements, Leaderboards y todo.
Pero cuando se me conecta algun amigo de OpenFeint, me mandan un mensaje, desbloqueo algun logro o algo, la notificacion me sale mediante el sistema de OpenFeint y no el tuyo…y no se porque.
Los metodos - (BOOL) isOpenFeintNotificationAllowed: y - (void)handleDisallowedNotification: no son lanzados en ningun momento, porque tengo NSlogs dentro y no se muestran en ningun momento por consola..Lo mirare con mas calma y vere, mientras voy a pasar a otra cosa a ver si se me ilumina la bombilla. Gracias de todos modos crack.
Posted 2 years ago # -
jeje harto del ingles :)
pues yo no te entendí muy bien, ya que es algo bastante raro ¿? yo lo tengo integrado de modo que nunca salen las notificationes openfeint y siempre las otras. voy a comparar lo tuyo con lo mio a ver que ocurre :)
un saludo.Posted 2 years ago # -
@manucorporat - thanks for this - its awesome! I'm still on the fence about adding openfeint but I'm using your code in my app and its working great. The only change I'll make is to create a new method that is not timed but will wait for a touch before hiding.
Just great, thanks again!
Cg
Oh, is there any other way to implement, other than altering CCDirector.m? I really like to keep my cocos2d files unmodified. If not then I'll just have to remember to patch each time I update cocos2d. Hmm, could I subclass drawScene?
Did I say thanks? well thanks again! :-]
Posted 2 years ago # -
Good luck with your game :)
Yes, I could subclass CCDirector, but probably you must rewrite all your code using CCDirectorWithNoti(for example) instead of CCDirectorPosted 2 years ago # -
New version of CCNotifications:
NEW - CACHED NOTIFICATIONS (wait until done)This method is deprecated.
- (void) addSafelyWithTitle:(NSString*)title message:(NSString*)message image:(NSString*)image tag:(int)tag animate:(BOOL)animate;Now you can create notifications easily:
[[CCNotifications sharedManager] addWithTitle:@"Notification sample" message:@"I wait until done" image:nil];Download it:
(with example code)http://github.com/manucorporat/CCNotifications/zipball/master
Posted 2 years ago # -
cocos2d v0.99.5 will include "native" support for notifications objects, like
CCNotifications.So, instead of patching the
CCDirector, you can do this:CCNotifications *notifications= [CCNotifications sharedManager]; [[CCDirector sharedDirector] setNotificationNode:notifications];github:
http://github.com/cocos2d/cocos2d-iphone/commit/fcf0be00d45d8efd711f8d13e3a2d3f6392fc3fbPosted 2 years ago # -
Good idea riq!!
I will update the CCNotifications code in some days.Now the integration with cocos2d is super easy!!!
// Init cocos2d CC_DIRECTOR_INIT(); //Init CCNotifications CCNotifications *notifications= [CCNotifications sharedManager]; //Add CCNotifications to cocos2d loop [[CCDirector sharedDirector] setNotificationNode:notifications]; //Show a notification [notifications addWithTitle:@"Test 1" message:@"Hello world!!!!" texture:nil];Posted 2 years ago # -
It's good that Rig has added the hook.
Before this was introduced, I was also able to get this around by using objective-c's Category - by creating CCDirector+drawScene.m since I didn't want to change CCDirector directly.@manucorporat, Thanks for the great code!
I am able to get some default notifications displayed on my screen. This works great!
By the way, I am having some hard time trying to show images from my preloaded CCSpriteBatchNode.
I don't seem to find an example on your example code though.
Can you show how to design a custom Notification template using CCSpriteBatchNode?Here's how I initialized my spritesheet:
NSString *imgName = @"test"; // For Jump animation: Create our sprite sheet and frame cache sharedInstance.spriteSheet = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"%@.png", imgName] capacity:10] ; [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist", imgName]];thanks again!
Posted 2 years ago # -
When you include CCNotifications in your game, there are 4 files:
Engine:
CCNotifications.h
CCNotifications.mNotification template:
notificationDesign.h
notificationDesign.mYou should modify the notificationDesign files.
- You can change the text size, position, rotation etc.
- You can add a background image or a sprite animation
- You can change the notification size
.....notificationDesign is a simple CCNode but it's conform with CCNotificationDesignProtocol to be compatible with CCNotifications.
You can use all cocos2d features in a notificationDesign.m, EVEN A PARTICLE SYSTEM!!!!
Posted 2 years ago # -
Thanks Manuel for having shared your code, it's very useful.
Posted 2 years ago # -
I just included this in my upcoming game (soon to be announced here) - great work @manucorporat!
I added a particle system to my notification popup (or pop down actually) which added a lot of depth to it.
To keep the particles constrained to the notification I added the following method to notificationDesign.m:- (void) visit { glEnable(GL_SCISSOR_TEST); glScissor((self.position.y) - 38, 0, 38, 480); [super visit]; glDisable(GL_SCISSOR_TEST); }Using the above, all particles get cut off at the bounds of the notification box which definitely adds to the effect.
Note that the above works only for landscape mode left. You will need to change the glScissor(...) function call if you are using the portrait modes or the other landscape mode.
Posted 2 years ago # -
Moved to extensions subforum.
I dont know how CCNotifications should be included in cocos2d - as a part of main repo, or as a part of extensions repo?Posted 1 year ago # -
How does one use the notification design template? I cant use the setTitle method that is under notificationsDesign.
Posted 10 months ago #
Reply
You must log in to post.