Lua Brigde - Custom Leaderboard?

The codes to integrate with Apple GameCenter via Native Extension is very straightforward. Personally I love the cloud build for native extension.

I’m implementing Game Center authentication feature for OSX. I’ve already got the Game Center login window. However, when entering my apple id account, the game halts when I tried to login.

https://s10.postimg.org/q8tymadm1/Screen_Shot_2017-07-18_at_12.00.45_AM.png

Not sure if it is a code sign problem or b/c of the View Controller used to present the authentication Controller as it’s not able to have an instance of the rootViewController as normal application.

Below is the code getting the view controller :

NSViewController *controller = [NSApplication sharedApplication].keyWindow.contentViewController;

2 Likes

Look like there’s problem with the ViewController which presenting the View Authentication Controller.
I’ve tested both in OSX and iOS. When the user was logged in, there’s no problem. The problem occurs when user enters account information and login via the authentication window.

The codes getting the authentication controller is similar in iOS :

#if defined(DM_PLATFORM_IOS)
UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController;
#else
NSViewController *controller = [NSApplication sharedApplication].keyWindow.contentViewController;
#endif

*** OSX**

https://s9.postimg.org/cqx8xnspr/gamecenter.png

*** iOS**

https://s9.postimg.org/eww55wljz/IMG_5307.png

1 Like

Could you perhaps use the dmGraphics::GetNativeOSXNSWindow and dmGraphics::GetNativeiOSUIWindow functions defined in dmGraphics to get the native window and from there get the view controller?

2 Likes

Thanks @britzl

I updated the codes to use dmGraphics, still got the same issues. Actually, I can’t get login window for both old and new codes for iOS. However, If the game center account has been already logged in, it works. The problem which lead me hold off other implementation is how to show the login view. Below is the quick replacement using dmGrahphics :

#if defined(DM_PLATFORM_IOS)
UIWindow *window = dmGraphics::GetNativeiOSUIWindow();
UIViewController *rController = window.rootViewController;
#else
NSWindow *window = dmGraphics::GetNativeOSXNSWindow();
NSViewController *rController = window.contentViewController;
#endif

Perhaps, I will clean the codes and push it to github for public review.

The codes to present authentication view controller :

[rController presentViewController:
       self.authenticationViewController
                          animated:YES
                          completion:nil];

The above tests using app bundle. I got the following error when “Build and Launch” (live run)

dmengine[15597:5506478] +[NSXPCSharedListener endpointForReply:withListenerName:]: an error occurred while attempting to obtain endpoint for listener ‘com.apple.view-bridge’: Connection interrupted

I pushed the whole code for Game Center native extension here :

https://github.com/vinhvd/defoldgamecenter

Honestly, I’m new for Lua and Object C and rarely write C/C++. Hope to have your supports to get the implementation.

3 Likes

Thanks for sharing! I’m away on vacation and will only have sporadic computer access, but hopefully someone in the community might be able to take a look.

1 Like

Thanks @britzl, have a great vacation.

I passed over the “game halt” issue. However, I’m still face with the following problem.

  • The implementation works good when the user has been logged in.
  • Login window display accepts input, but nothing happens when logging to for OSX. The login window still doesn’t display for both development and production provision.

Just update that the authentication for OSX works OK now.

That’s good to hear! What did you do to solve it?

That was a mistake when declaring instance variables using @properties instead of @private/@public. After fixing them, I tested the OSX build using wrong bundle identity(for iOS) so it was not enable to login to Game Center. Up to now, the common usage API for OSX work great (.e.g login, report scores , show leaderboard, show achievement)

2 Likes

I forked your library and made it into a Defold library, so if you see a pull request from a random GitHub person, that would be me :rofl:

4 Likes

Thanks Gregor,
Good catch.