Sign In Register

How can we help you today?

Start a new topic
Answered

Referencing gsInstance in Cocos2d-x?

Please forgive me if this question is overlooking an incredibly basic GameSparks concept. I'm new to the platform and loving its capabilities so far, but have been stumped by this.


I've followed the examples established with the Cocos2d-x SDK and they have been very useful in establishing device registration and simple connection to GameSparks. However, I'm trying to implement Facebook Login as well. The Login works, and my plan was to have the successful login trigger the GameSparks authentication with the new token (GameSparks automatically checks for a FaceBook token on startup, but I wanted to have a FB login trigger it, as well).


I'm noticing that many of the request functions for GS require the passing in of a gsInstance argument. This makes sense, as the code needs to know which GS connection to pass the arguments through. However, I've looked over the API reference and cannot find a way to reference the active gsInstance, which looks like is initialized on startup in the AppDelegate header as it is in the example project.


My strategy was going to be creating an extern variable to reference the gsInstance, and pass that in with any functions that require it, but I wanted to make sure this doesn't create some kind of security risk. I also wanted to make sure that I'm not overlooking some simple getter function for the gsInstance.


Thank you!


Best Answer

Hi Matthew,


I can think of 2 ways to get around this problem. One of which being you create a new gsInstance pointing to the gsInstance in the AppDelegate header. You could wrap this up in a Singleton, or pass it throughout your application downstream (this is preferred for reasons I'll discuss later).


Another method would be to get the current instance of the AppDelegate whenever you need to by turning it into a Singleton. For more information on this design pattern please look here. There is also a sample implementation of this method in Cocos2dx here.


Bear in mind that there is a lot of opinions on the prevailing use of Singelton's in games.


The Cocos2dx examples are being updated shortly so we will have more thorough documentation available for you soon.


I hope I was able to help with your issue, if not please let me know and I will continue investigating your issue.


-Pádraig


Hi Matthew,


We're looking into this for you and will update you shortly,


-Pádraig

Great, thanks so much! I've never dealt with an object instantiated through a private struct in the AppDelegate before, so I'm not sure as to which coding conventions are appropriate to deal with it. 

Answer

Hi Matthew,


I can think of 2 ways to get around this problem. One of which being you create a new gsInstance pointing to the gsInstance in the AppDelegate header. You could wrap this up in a Singleton, or pass it throughout your application downstream (this is preferred for reasons I'll discuss later).


Another method would be to get the current instance of the AppDelegate whenever you need to by turning it into a Singleton. For more information on this design pattern please look here. There is also a sample implementation of this method in Cocos2dx here.


Bear in mind that there is a lot of opinions on the prevailing use of Singelton's in games.


The Cocos2dx examples are being updated shortly so we will have more thorough documentation available for you soon.


I hope I was able to help with your issue, if not please let me know and I will continue investigating your issue.


-Pádraig

Hey Matthew,

Did this help you sort out your problem?

Sean

 

Hi! This did, thank you very much!

Login to post a comment