HOW TO (SHOULD I?) PORT FROM iOS GAMECENTER/IN-APP PURCHASE (APPLE) TO ANDROID (GOOGLE)


#1

HOW TO (SHOULD I?) PORT FROM iOS GAMECENTER (APPLE) TO ANDROID (GOOGLE)?

I have developed a few Cocos2D games with GameCenter and IAP support which is easily done with some third-party libraries and Apple apps examples, BUT now I’m trying to develop some MULTI-PLATFORM games for iOS and ANDROID so I’m thinking about Cocos2D-X solution, BUT I’m concerned about the specific platform issues like score counting, leaderboards and in-app purchases, so I can make a really multi-platform game with leaderboards and in-app purchases work smoothly.

Any thoughts or advices?

Thanks,
Carlos

PS. I’m in the process of IDEA AND DESIGN of the game so I’m making the research


#2

I added JNI files to invoke Play Game Services and Google IAP.

  • Ranking.h - it is used by .mm and .cpp both.
  • Ranking.mm - it is for GameCenter.
  • Ranking.cpp - it has JNI codes to invoke Java stuffs.
  • Ranking.java - It includes static methods for PlayGameServices.

#3

@dalinaum where do I get those files ? are part of Cocos2D-X ? or a third-library or your own?


#4

I made all codes for my game. I think you can make your own files too.

Here is some example.

java

	public static void gameServicesSignIn() {
		((ZombieAway) mContext).runOnUiThread(new Runnable() {
			@Override
			public void run() {
				((ZombieAway) mContext).beginUserInitiatedSignIn();
			}
		});
	}

cpp

bool gameServicesSignIn() {
  cocos2d::JniMethodInfo t;
  if (cocos2d::JniHelper::getStaticMethodInfo(t,
                                              "com/lazybeeinc/ZombieAway/ZombieAway",
                                              "gameServicesSignIn", "()V")) {
    t.env->CallStaticVoidMethod(t.classID, t.methodID);
    t.env->DeleteLocalRef(t.classID);
  }
  return true;
}

mm

bool gameServicesSignIn() {
  if (!isGameCenterAvailable()) {
    CCLOG("startGameCenter Faile");
    return false;
  }
  authenticate();
  CCLOG("startGameCenter OK");
  return true;
}

void authenticate() {
  GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
  [localPlayer authenticateWithCompletionHandler:^(NSError *error) {
    if (localPlayer.isAuthenticated) {
      NSLog(@"Alias : %@", localPlayer.alias);
      NSLog(@"Player ID : %@", localPlayer.playerID);
      hasLogIn = true;
    } else {
      NSLog(@"error: %@", error);
      NSDictionary *userInfo = [NSDictionary dictionaryWithObject:error forKey:@"NSError"];
      for (id key in userInfo) {
        NSLog(@"key: %@, value: %@ \n", key, [userInfo objectForKey:key]);
      }
    }
  }];
}

#5

You can use SOOMLA… it is pretty good… takes a bit of use to and supports 2.2.2 as of now I think… but will help you save time writing code…


#6

Now you can use Google Play Games C++ SDK [https://developers.google.com/games/services/cpp/GettingStartedNativeClient]
to implement authentication, leaderboards and achievements. This is working on iOS as well, so I think this is correct approach.


#7

It looks to me like @krinsen’s answer is right.

The Google Play Games C++ SDK provides a C++ API for use with Google Play game services, and is meant for developers who have an existing C++ implementation of their game. It is especially geared toward providing easy portability between Android and iOS.

I will delete JNI codes.