Game Development Community

Open Feint Tutorial

by Eyal Erez · in iTorque 2D · 10/25/2009 (1:04 pm) · 94 replies

So after receiving help from so many people on how to set up Open Feint, I figure I’ll make a beginners guide and place all of the different bits together in one thread. I’d like to thank Kevin Ryan , Ronny Bangsund , Sven Bergström , Craig Fortune and John Sear for their help. they did all the work and for most of it, I just copy and paste :) Hope I didn’t forget anyone.

So the first steps are getting the open feint sdk integrated.
Follow these steps http://help.openfeint.com/faqs/guides-2/integrating-the-openfeint-sdk

Step #7. go to you project dir and open iTGB_Prefix.pch and add the prefix.
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "OpenFeintPrefix.pch"
#endif

now build and you will probably get an error. open iPhoneMemory.mm and change the to that:
#ifndef TORQUE_DISABLE_MEMORY_MANAGER
void* FN_CDECL operator new(dsize_t dt, void* ptr)
{
	return (ptr);
}   
#else
#include "new"
#endif

in platform.h you need to change extern void* FN_CDECL operator new(dsize_t size, void* ptr); to that:
#ifndef TORQUE_DISABLE_MEMORY_MANAGER
extern void* FN_CDECL operator new(dsize_t size, void* ptr);
#else
#include <new>
#endif
now you should be able to build with no errors.
Now here's my TGBAppDelegate.mm without the productId and secret which you should replace with yours. please note that I placed the console functions here where ideally they should be placed in consoleFunctions.mm
#import "TGBAppDelegate.h"
#include "platform/platformInput.h"

extern void _iPhoneRunTorqueMain( id appID,  UIView *Window, UIApplication *app );
extern void _iPhoneGameInnerLoop();
extern void _iPhoneGameResignActive();
extern void _iPhoneGameBecomeActive();
extern void _iPhoneGameWillTerminate();
extern void _iPhoneGameChangeOrientation();

#define OPEN_FEINT

#ifdef OPEN_FEINT  
#import "OpenFeint.h"  
#import "OFHighScoreService.h"  
#import "OFHighScore.h"  
#import "OFAchievementService.h"  
#import "OFAchievement.h"  
#import "OpenFeint+Dashboard.h"  
#import "Achievements.h"
#endif  

@implementation TGBAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	_iPhoneRunTorqueMain( self, window, application );
	
	// http://www.garagegames.com/community/forums/viewthread/98361/3#comments
	
	
	
    NSString *productKey = @"Your_key";  
    NSString *secret = @"your_secret";  
    NSString *displayName = @"your_game";  
	
    NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:  
                              [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation,  
                              [NSNumber numberWithBool:YES], OpenFeintSettingDisableChat,  
                              nil  
							  ];  
	
    [OpenFeint initializeWithProductKey:productKey  
                              andSecret:secret  
                         andDisplayName:displayName  
                            andSettings:settings  
                           andDelegates:nil];  
	
	 
	 
}


bool OpenFeintIsOn = false;

- (void)applicationWillResignActive:(UIApplication *)application {
	_iPhoneGameResignActive();	
	[OpenFeint applicationWillResignActive];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
	_iPhoneGameBecomeActive();
	[OpenFeint applicationDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application {
	_iPhoneGameWillTerminate();
}


- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation{
	_iPhoneGameChangeOrientation();
}

- (void) runMainLoop {
	_iPhoneGameInnerLoop();
}

- (void)dealloc {
	[window release];
	[super dealloc];
}



- (void) dashboardWillAppear
{  
    
	OpenFeintIsOn = true;
}  

- (void) dashboardWillDisappear
{  
    
	OpenFeintIsOn = false;
}  


 
void launchOpenFeintDashboard(S32 dashboardType)  
{  
    if (dashboardType == 0)  
		[OpenFeint launchDashboard];  
    else if (dashboardType == 1)  
		[OpenFeint launchDashboardWithAchievementsPage];  
    else if (dashboardType == 100)  
    {  
		NSString *leaderboardId = @"37873";  // Beginner  
		[OpenFeint launchDashboardWithHighscorePage:leaderboardId];  
    }  
	else if (dashboardType == 101)  
    {  
		NSString *leaderboardId = @"37883";  // Advanced
		[OpenFeint launchDashboardWithHighscorePage:leaderboardId];  
    }  
	else if (dashboardType == 102)  
    {  
		NSString *leaderboardId = @"56223";  // Expret 
		[OpenFeint launchDashboardWithHighscorePage:leaderboardId];  
    }  
}  


void submitOfScore(S32 score, S32 leaderboardNum)  
{  
    NSString *leaderboardId = @"37873";    

    if (leaderboardNum == 1)  leaderboardId = @"37883" ;   
    else if (leaderboardNum == 2) leaderboardId = @"56223" ; 		
	
    [OFHighScoreService setHighScore:score  
					  forLeaderboard:leaderboardId  
						   onSuccess:OFDelegate()  
						   onFailure:OFDelegate()];  
}  


void awardOfAchievement(S32 awardedNum)  
{  
    if (awardedNum == 1)  
        [OFAchievementService unlockAchievement:LIGHT_SPEED];  
	else if (awardedNum == 2)  
        [OFAchievementService unlockAchievement:STARGAZER]; 
	else if (awardedNum == 3)  
        [OFAchievementService unlockAchievement:COMBO_KING]; 
	else if (awardedNum == 4)  
        [OFAchievementService unlockAchievement:BRONZE_MEDAL]; 
	else if (awardedNum == 5)  
        [OFAchievementService unlockAchievement:SILVER_MEDAL]; 
	else if (awardedNum == 6)  
        [OFAchievementService unlockAchievement:GOLD_MEDAL]; 
	else if (awardedNum == 7)  
        [OFAchievementService unlockAchievement:SPACESHIP_DESTROYER]; 
} 




ConsoleFunction(launchOpenFeintDashboard, void, 2, 2, "launchOpenFeintDashboard(leaderboardNum) "  
                "launches the open feint dashboard")  
{  
    argc;  
	
    launchOpenFeintDashboard( dAtoi(argv[1]) );  
}  



ConsoleFunction(submitOfScore, void, 3, 3, "sumbitScore(score) "  
                "awards the passed achievement")  
{  
    argc;  
	
    submitOfScore( dAtoi(argv[1]),dAtoi(argv[2]) );  
} 


ConsoleFunction(awardOfAchievement, void, 2, 2, "awardOfAchievement(awardNum) "  
                "awards the passed achievement")  
{  
    argc;  
	
    awardOfAchievement( dAtoi(argv[1]) );  
}  


bool isOpenFeint()
{
	return OpenFeintIsOn;
}



@end

I've also add the following line to TGBAppDelegate.h
bool isOpenFeint(void);

The isOpenFeint function is used in iPhoneMain.mm to stop the mainLoop from running when openFeint window is open. Here's the hack :
void _iPhoneGameInnerLoop()
{
	if(Game->isRunning()){
		S32 start = Platform::getRealMilliseconds();
		if( isOpenFeint() == false)
		{
			Game->mainLoop();
		}
		S32 time = sgTimeManagerProcessInterval - (start - gLastStart);
		gLastStart = start;
		iPhoneRunEventLoopTimer(time);
	}
	else
	{
		Game->mainShutdown();
	}
}

For the Achievements you will need to add them on your dashboard and add the achievements.h to you project as well as offline support if you like.

This should be it, unless I forgot anything.
Please help me improve it with your insights.
Page«First 1 2 3 4 5 Next»
#81
10/10/2010 (11:33 pm)
Cool stuff. Selvin reads docs so I don't have to!

I haven't investigated Game Center's API at all yet (busy with a desktop game + tools), but does it have the same sort of in-game control panels, or is it all code to call and get responses from, build your own GUI?
#82
10/11/2010 (9:41 am)
@Ronny: that's what I will try to find out. As we do for OpenFeint by calling [OpenFeint launchDashboard]; there should be a function that open Game Center within your app and it should give you the in game panels.

@Scott: I used mainly your code to integrate OpenFeint. I started working on Achievement (Leaderboard done and it works fine) and I noticed that when I call the method awardOfAchievement, the notification pop up from the top doesn't appear (but I can see the achievement unlocked from the OpenFeint dashboard).
Do you have the same behavior?
It could be related to the new achievement percentage functionality available in OF2.7 (the one I use), here what they say in the documentation:

Quote:
How To Unlock an Achievement in an iPhone App using an OpenFeint 2.7 or newer SDK

OpenFeint 2.7 introduced the ability to partially unlock achievements with a percentage completion. Only when the percentage completion reaches 100% is the achievement is considered unlocked.

The following example shows how to unlock an achievement completely in one step without bothering to show a notification:

[[OFAchievement achievement: achievementId] updateProgressionComplete: 100.0f andShowNotification: NO];

Note: that you may call this unlock function more than once. It will only have an affect the first time it is unlocked for a player.

Of course I will have to use andShowNotification: YES, but not sure how to change your code:

OFAchievement *myAchievement = [OFAchievement achievement:(NSString*)achievementId];
//NSLog(@"------- [%@], [%@]", [myAchievement title], [myAchievement description]);
[myAchievement unlock];

Something like:

[[OFAchievement achievement: (NSString*)achievementId] updateProgressionComplete: 100.0f andShowNotification: YES];
#83
10/11/2010 (10:37 am)
Selvin, not switched to 2.7 yet - finding it difficult to keep up with the OF releases ! On the face of it your suggestion looks correct to me, is it not working?
#84
10/11/2010 (10:51 am)
Scott,

I found out about achievement percentage this morning looking for a reason why the notification wasn't showing up, I will try the code tonight and let you know.

Can you confirm you get a notification for achievement with your OF version?
#85
10/11/2010 (3:23 pm)
Yep, we do.
#86
10/11/2010 (9:07 pm)
I tested the new way of award achievement and it works. Here the small adjustment:

void awardOfAchievement(const char* award) {
NSString *achievementId = [[NSString alloc] initWithUTF8String:award];
//[OFAchievementService unlockAchievement:achievement];

TGBAppDelegate *delegate = (TGBAppDelegate*)[[UIApplication sharedApplication] delegate];
[OFAchievement setDelegate:delegate];
//OFAchievement *myAchievement = [OFAchievement achievement:(NSString*)achievementId];
//[myAchievement unlock];
//NSLog(@"------- [%@], [%@]", [myAchievement title], [myAchievement description]);
[[OFAchievement achievement: (NSString*)achievementId] updateProgressionComplete: 100.0f andShowNotification: YES];

}

This is the code in case you want to create a console function from which it will be opened the Game Center within your game:

http://openfeint.com/developers/forum/showthread.php?2353-Testing-game-center-with-openfeint

Still haven't looked into integrating in iTGB and we are not sure if it is a good idea, probably it will be confusing. The players know that their OpenFeint account is linked to GameCenter (when they open the game the first time) and that all Leaderboard and Achievement are updated in both.
#87
04/05/2011 (3:28 am)
***solved
#88
07/04/2011 (3:37 pm)
@Eyal. Thanks for the post.

@Scott.

Quote:Let me know if you want to use any of the social stuff e.g. FaceBook and I can provide calling examples from Torque.

Yes, I'm interested in the Facebook calls. Could you post them? Thanks.
#89
10/26/2011 (1:27 am)
Can anyone update this tutorial to the last Open Feint Version?

Thanks
#90
01/18/2012 (10:42 pm)
Okay, I think I have iT2D 1.5 working with OF 2.12.5. I've moved most of the functions to a separate delegate class taken from the sample OF application.

1. Add OpenFeint to your project.
support.openfeint.com/dev/readme-for-openfeint-ios-sdk-2-12-5/#enable
checklist:
* add OpenFeint.framework
* add OFResources configuration bundle
* add -all_load -ObjC flags
* add additional frameworks
AddressBook
AddressBookUI
CFNetwork
CoreGraphics
CoreLocation
CoreText
Foundation
GameKit
libsqlite3.0.dylib
libz.1.2.3.dylib (unless using the compiler flag OF_EXCLUDE_ZLIB to turn off compression of high score and cloud storage data blobs.)
MapKit
MobileCoreServices
QuartzCore
Security
SystemConfiguration
UIKit


2. Add OFDelegate.h and OFDelegate.mm to your project
s87051801.onlinehome.us/Torque/OFDelegate.zip

3. Make changes to platformiPhone/TGBAppDelegate.h
#import "OpenFeint/OpenFeintDelegate.h"

@class SampleOFDelegate;

@interface TGBAppDelegate : NSObject <UIApplicationDelegate> {
	IBOutlet UIWindow *window;
	SampleOFDelegate *ofDelegate;

4. Make changes to platformiPhone/TGBAppDelegate.mm

add
#define OPEN_FEINT  
#define OPEN_FEINT_GAMEFEED

#if defined( OPEN_FEINT )
#import "OpenFeint/OpenFeint.h"    

#import "OFDelegate.h"
#import "OpenFeint/OFInvocation.h"
#import "OpenFeint/OFUserSettingService.h"
#import "OpenFeint/OFHighScoreService.h"    
#import "OpenFeint/OFHighScore.h"    
#import "OpenFeint/OFAchievementService.h"    
#import "OpenFeint/OFAchievement.h"    
#import "OpenFeint/OpenFeint+Dashboard.h"    
#endif

add to the end of applicationDidFinishLaunching
#if defined(OPEN_FEINT)
//    
//    // http://www.garagegames.com/community/forums/viewthread/98361/3#comments  
//    

	NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
							  [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation,
							  @"displayName", OpenFeintSettingShortDisplayName,
							  [NSNumber numberWithBool:YES], OpenFeintSettingEnablePushNotifications,
							  [NSNumber numberWithBool:YES], OpenFeintSettingDisableUserGeneratedContent,
  							  [NSNumber numberWithBool:NO], OpenFeintSettingAlwaysAskForApprovalInDebug,
#ifdef DEBUG
                              [NSNumber numberWithInt:OFDevelopmentMode_DEVELOPMENT], OpenFeintSettingDevelopmentMode,
#else
                              [NSNumber numberWithInt:OFDevelopmentMode_RELEASE], OpenFeintSettingDevelopmentMode,
#endif
							  window, OpenFeintSettingPresentationWindow,
#ifdef DEBUG
							  [NSNumber numberWithInt:OFDevelopmentMode_DEVELOPMENT], OpenFeintSettingDevelopmentMode,
#else
							  [NSNumber numberWithInt:OFDevelopmentMode_RELEASE], OpenFeintSettingDevelopmentMode,
#endif
							  nil
							  ];
    
    ofDelegate = [SampleOFDelegate new];
    
    OFDelegatesContainer* delegates = [OFDelegatesContainer containerWithOpenFeintDelegate:ofDelegate  
                                                                      andChallengeDelegate:nil  
                                                                   andNotificationDelegate:nil];  
    
    NSString *productKey = @"productKey";    
    NSString *secret = @"secret";    
    NSString *displayName = @"displayName";    

    [OpenFeint initializeWithProductKey:productKey      
                              andSecret:secret      
                         andDisplayName:displayName      
                            andSettings:settings 
                           andDelegates:delegates]; 
#endif // OPEN_FEINT

add to the end of applicationWillTerminate
#if defined(OPEN_FEINT)
    [OpenFeint shutdown];
#endif
#91
01/24/2012 (11:21 am)
Hei can't download this :

www.filesonic.com/file/eTT6Sxg/OFDelegate.zip


why ??

Can you link here other sever ???

thanks
#92
01/24/2012 (10:51 pm)
Sorry, looks like filesonic had a panic attack after Megaupload got shut down and they've closed up all file sharing, legit or otherwise.

I've copied the files to my own page, they should be good there. Let me know if you still have problems.
#93
05/23/2012 (11:14 am)
OpenFeint is now GREE. What impact will this have on iTorque games using OF?
#94
05/24/2012 (9:25 am)
Looks like someone at GREE wants to answer that question...

Migrate OpenFeint on the GREE site.

It appears that it is "free" to use the GREE platform until you publish, and then it looks like they skim from your microtransactions as shown in the GREE Developer Agreement, Appendix II.

I only did a quick dive on the site, but it looks like you can continue to use OpenFeint without issue - I'm no lawyer, so don't take this as legal advice.
Page«First 1 2 3 4 5 Next»