Binding succeed but can't not call functions in my scene///// Gamecenter not working

Sorry guys, here is for c++ topics, but I feel my questions can get more attention here.
I’ am debugging this the whole weekend and couldn’t find a solution for it.

I am trying to enable Game Center to my application and I’ve set up game in itune connect
and enabled gamecenter for it. In game, I set up correct bundle id.
My phone is not jailbreak.

  1. Here is the Gamecenter code I am using :

GameKitHelper.h

#ifndef GameKitHelper_h
#define GameKitHelper_h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>

@interface GameKitHelper :  NSObject <GKLeaderboardViewControllerDelegate, GKAchievementViewControllerDelegate, GKMatchmakerViewControllerDelegate, GKMatchDelegate>{
    BOOL gameCenterAvailable;
    BOOL userAuthenticated;
}

@property (assign, readonly) BOOL gameCenterAvailable;

+ (GameKitHelper *)sharedGameKitHelper;
- (void) authenticateLocalUser;

- (void) reportScore: (int64_t) score forCategory: (NSString*) category;

- (void) showLeaderboard;
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController;

@end


#endif

Below is reportScore functions implementation:

- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
    scoreReporter.value = score;
    
    NSLog(@"I am inside report Score");
    
    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            // handle the reporting error
        }
    }];
}

  1. I wrote a wrapper class in C++:
#include "cocos2d.h"
#include "ScriptingCore.h"



namespace ls{
    
    
    class GameCenterBridge: public cocos2d::CCObject{
        
    public:
        
        static cocos2d::CCScene* scene();
        virtual bool init();
        
        CREATE_FUNC(GameCenterBridge);
        
        void pushscore(string score, string category);
        
    };

}

  1. Then I call the native object c code:
void ls::GameCenterBridge::pushscore(string score,string cat){
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    
    cout<<"I AM WORKING+++++++++++++++++++++++"<<endl;
    
    NSString* result = [NSString stringWithUTF8String:cat.c_str() ];
    
    NSString* s = [NSString stringWithUTF8String:score.c_str() ];
    
    int64_t i = [s longLongValue];
    
    [MyGameCenterManager reportScore:(i) forCategory:(NSString *) result];
    
    
#endif
    
}
  1. I called following code in AppController.mm:
  //Game Centre
    [[GameKitHelper sharedGameKitHelper] authenticateLocalUser];
    
    [[GameKitHelper sharedGameKitHelper] showLeaderboard];

5 ) Then I bind it :


#include "jsapi.h"
#include "jsfriendapi.h"
#include "ScriptingCore.h"


void register_all_ls(JSContext* cx, JSObject* obj);



  1. I registered it in AppDelegate.cpp:

    sc->addRegisterCallback(register_all_ls);

  2. when I used following code in cocos2d-jsb.js:

cc.log(“I am pusing”);
var ls = ls.GameCenterBridge.create();
ls.pushscore(“30”,“scoreboard”);

  1. in the log, I saw it succeed.

However I got following issues:

a) I cannot use var ls = ls.GameCenterBridge.create(); in my scene js files under src folder.

I got console saying: ls is undefined. Just wondering, how could I include self-binding classes to scene js?

b) when i run application in ios6, it is saying i am in sandbox mode. The leaderboards is empty.

in ios7, a pop up saying: Game Center unavailable, player is not signed in

I’ve set up game center in itune connect and also set same bundle id for it, and compile the project correctly
I even got NSLOG from report score function. But looks like nothing has happened.

just wondering, if there is something wrong with my calling of gamecenter?

following is the log i got when i run application:

Cocos2d: JS: I am pusing

Cocos2d: js ls lsleafsoar create …
Cocos2d: gamecenter init …
2014-03-02 21:04:00.961 flappy[64211:70b] Hello, World!
2014-03-02 21:04:00.962 flappy[64211:70b] I am inside report Score
2014-03-02 21:04:00.966 flappy[64211:70b] cocos2d: surface size: 640x1136
Cocos2d: JS: my scene

OK. Just figure out I have to new it before use.

But, still couldn’t push score into leaderboard. sad.

ok. Fixed it by myself. LOL.

can you tell me how you fixed that? :slight_smile: