LibGDX and google-mobile-ads Robopods integration (iOS)

I just started porting my existing android game (word-hunter) to iOS and ran into a lot of troubles trying to make adMob works on iOS with libgdx and robovm, so I figure someone else might need this :)

You should probably already have an Interface in your libgdx core project to specify the actions correspond to the display of ads:

public interface AdsDisplayInterface{
   public void loadAd();
   public void showAd();
}

And your game constructor should expect an implementation of this interface as argument:

public class Game implements ApplicationListener {
   ...
   public AdsDisplayInterface _adsDisplay;

   public Game(AdsDisplayInterface adsDisplay){
      _adsDisplay = adsDisplay;
   }

   public Game(){
      ...
   }

   @Override
      public void create() {
      ...
   }
}

Now you can call _adsDisplay.loadAd() and _adsDisplay.showAd() anytime you want in your game, see this post for more details on how this works.

Now we want to create a class implementing this Interface in the platform where we want to display ads, in our case: iOS.

First we need to integrate the google-mobile-ads robopod binding (git repo).

Follow the instructions from the README in the git website and use either graddle or maven to add the binding.

I added compile “org.robovm:robopods-google-mobile-ads-ios:$roboVMVersion” in the dependencies of the project(“:ios”) in the main build.gradle of my libgdx projects, used ./gradlew eclipse and then imported the projects into Eclipse.

Another option if you don’t want to use graddle or maven is to directly grab the jar files you need (robopods-google-mobile-ads-ios-$robovmVersion.jar and robopods-google-apis-ios$robovmVersion.jar) from the robovm maven directory and add then to your ios project /lib folder (create it if necessary) and add both jar to the build bath.

Now we need to create an implementation of the AdsDisplayInterface in our ios project:

@CustomClass("ViewController")
public class ViewController implements AdsDisplayInterface {
 private GADInterstitial interstitial;

 private GADInterstitial createAndLoadInterstitial() {
     //Ad Unit ID of your interstital, from your adMob account. Use the TEST one for now
     GADInterstitial interstitial = new GADInterstitial("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx");
     interstitial.setDelegate(new GADInterstitialDelegateAdapter() {
         @Override
         public void didDismissScreen(GADInterstitial ad) {
             ViewController.this.interstitial = createAndLoadInterstitial();
         }
     });
     interstitial.loadRequest(createRequest());
     return interstitial;
 }

 private GADRequest createRequest() {
     GADRequest request = new GADRequest();
     // To test on your devices, add their UDIDs here:
     request.setTestDevices(Arrays.asList(GADRequest.getSimulatorID()));
     return request;
 }

 @Override
 public void loadAds() {
     interstitial = createAndLoadInterstitial();
 }

 @Override
 public void showAds() {
     if (interstitial.isReady()) {
         interstitial.present(UIApplication.getSharedApplication().getKeyWindow().getRootViewController());
     } else {
         System.out.println("Interstitial not ready!");
     }
 }

}

I used this sample application and modified a couple of things to make it work with libgdx. If you need to add banners, check the sample and it should be quite straightforward.

Now we need to modify our IOSLauncher in the libgdx IOS application:

public class IOSLauncher extends IOSApplication.Delegate {

 private GADInterstitial interstitial;

 @Override
 protected IOSApplication createApplication() {
     Words.setPlatformResolver(new DesktopResolver());

     IOSApplicationConfiguration config = new IOSApplicationConfiguration();
     return new IOSApplication(new Game(new ViewController()), config);
 }

 public static void main(String[] argv) {
     NSAutoreleasePool pool = new NSAutoreleasePool();
     UIApplication.main(argv, null, IOSLauncher.class);
     pool.close();
 }

And now it should work :) Your IOS ad will show up whenever you call loadAd() then showAd() in your game.

Hopefully I didn’t forget any steps, otherwise let me know !

New puzzle game! Gem Hunter

I’ve just finished the development of a small game I wanted to do in my spare time, much simpler than my previous game but it’s still quite fun to play.

logo

The game is obviously available for free on the google play store here: Gem Hunter

The game is quite simple, you try to line up rows/columns of the same color to make them dissapear and earn points, to do so, you can change a gem color by tapping on it, but when you do, a new gem appear on the board. Get as much points as you can before the board is full :)

As always, any feedback is welcome, I haven’t tested on all device yet :)

First major update to Word Hunter

It’s been a week since I published the first version of Word Hunter and it’s going quite well. The game is not perfect but I was able to get quite some feedback and act upon it :)

What’s new ?

  • 20 new levels (double of what was available before) with new gameplay mechanisms
  • New dragback mechanism: you can drag back on the previous letter to correct the word
  • 6 new achievements
  • Bug fix for the HTC One
  • Better handling of ads, they shouldn’t show up in game anymore

LVL 21 - New Cages       New gameplay mechanism

Word Hunter trailer !

I’ve created a trailer for Word Hunter !

It’s my first video recording/editing experience and it was quite interesting.

I recorded it using quick time and did all the video editing using iMovie. Both tools are available by default on all Mac Os installs (AFAIK)

  • Quick Time is fine for recording: the video quality is decent but not great and there is no option to hide the mouse during recording (but there is the option to show mouse clicks)
  • iMove is quite easy to pick up and quite frankly suits most of my needs as a beginner. It’s got a nice library of default effects which are quite nice. Really easy to add titles, transitions, effects and musics. Only downside is that you are limited to the transitions/titles available and can’t create your own. But this might be due to me being a total noob :)

Here it is :

The music is by Kevin McLeod at incompetch.com.

I still have a lot to learn about video editing so I am willing to listen to all feedback :)

LibGDX and Google Play Game Service Integration

I have been hard working on Google Play Game integration in my upcoming game : Word Hunter and I am posting my finding heres. Hopefully it can help someone else :)

Configuring Google Play Game

Log on to the developer console (if you don’t already have an account, you will need to create one for 25$)

Select “Game Services” and follow the instructions to create a new game.

Some notes :

    • Use the debug certificate in your android sdk install folder
      • You will be able to test Google Play Game integration directly when you launch your application from Eclipse without having to sign it with your production certificate
      • But you will have to restart the process all over again once you want to push it to production (…)
    • Use your production certificate that you use to publish your application to google play
      • You will need to sign your APK using your production certificate (right click on your project -> Export as Android Application) and then install this APK on your device to test it
      • And you are done, you can simply publish the game when you are done and it will work

I went with solution #2 since I am publishing my game in Alpha state in Google play and I want my testers to be able to use it

  • DO NOT forget to add your testers email in the list of testers for the GAME, it is a different list than the application testers or even the Alpha testers
  • Do not bother trying to test Google Play Game with your developer account, even if it is marked as a tester, it just doesn’t work. Use another account.

Once you are done, you should get an application ID associated to your game, follow this documentation to make it available in your game (short version, create an ids.xml file in the android res/values folder and add this id in it as a string with name app_id). This is also where you will put the key for your leaderboards/achievements. You will also need to modify your manifest as indicated in the documentation.

Configuring the libGDX Core project

In your Core project, create an interface with all the actions that you want to be able to do from your game. The basis are :

  • Logon
  • Logoff
  • Send a score to the leaderboard
  • Unlock an achievement
  • Show the Score Leaderboard
  • Show the Achievements Screen

Pastebin code

Configuring the Android project

Once this is done, we need to do several things:

First follow the instructions to download the sample apps from here .

You should get the google-play-services-lib when you install the google play service SDK. Add it to your workspace and add it to your Android project as a library (right click on your android projects -> Properties)

From the BaseGameUtils projects, copy the GameHelper.java class directly into your Android project.

Now we will modify the Android project MainActivity class.

First it needs to implement the previously created interface, as well as the GameHelper.GameHelperListener interface (from the GameHelper class we just copied) :

public class MainActivity extends AndroidApplication implements LeaderboardInterface, GameHelper.GameHelperListener

In this class, we will need to instantiate a GameHelper and implement the different methods specified in the Interface. Most of this code was inspired/copied from the BaseGameActivity available in the sample Android project.
Once this is done, we need to pass the MainActivity itself as an argument of the initialize method.

Here is the code

Possible improvements :

  • Show a toast when the unlockAchievement method is called by user is not logged in google play
  • Push scores and achievements right after login, in the onSignInSucceeded method

I noticed that by using this method, the Title Bar now appears in game. To solve this issue, simply add the following theme to your main activity in the manifest :

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

How to use it in game

In your main class in the core libGDX project (the one which implements ApplicationListener), create a variable of type GameServiceInterface and set it using the arguments passed in the constructor :

public class Game implements ApplicationListener {

public GameServiceInterface _leaderboard;

public Game(GameServiceInterface leaderboard){

         this._leaderboard = leaderboard;

}

And now you can just call/bind _leaderboard.login() or any other method of the GameServiceInterface anytime in your game.

LibGDX and RevMob integration

I figured I would do a small tutorial on this subject since I had to implement it recently on my current project.

I want to display Full Screen RevMob ad in my Android game in between two levels. Displaying banner ads is slightly different and won’t be covered here.

Setup and configure RevMob

  1. First, grab the RevMob SDK from their website, for this tutorial, I will pick Android as the target platform. (You can also check the configuration step from their website for the most up to date instructions)
  2. Copy the revmob-n.n.n.jar in your android project libs’s folder and add it to your build path (in Eclipse, right click on the jar -> Add to build path)
  3. Modify your project’s manifest, add the following permissions
    • <uses-permission android:name="android.permission.INTERNET"/>
    • <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    • <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    • <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> (This one is optional but recommended)
  4. Add the following activity to your manifest (supposing you want to use full screen ads in your application)
    • <activity android:name=”com.revmob.ads.fullscreen.FullscreenActivity” android:configChanges=”keyboardHidden|orientation”> </activity>
  5. Also don’t forget to create your application in the RevMob console and grab your application ID

Configure LibGDX projects

Next you want to configure your LibGDX projects. Let’s suppose your game is multiplatform and you have an Android, Web, Desktop. You want to display RevMob ads only in your Android game and use another ads platform for Web/Desktop (since RevMob is mobile only) or maybe your desktop version won’t be displaying any ads anyway.

First let’s create an Interface in your main project to specify the actions correspond to the display of ads.

public interface AdsDisplayInterface{
   public void showFullScreenAds();
   public void openAdsLink();
}

This interface correspond to the different actions you might want to do in your game (for example show a full screen ads between two levels, or open the affiliate link when the “More Applications” button is clicked…)

Now you want to create a class implementing this Interface in the platforms where you want to display ads

In the Android project, we will create the following class

public class RevMobDisplay implements AdsDisplayInterface {
   private static final String REVMOB_APP_ID = &quot;copy your RevMob App ID here&quot;;
   private MainActivity activity;
   private RevMob revmob;

   public RevMobDisplay(MainActivity mainActivity){
      this.activity = mainActivity;
      revmob = RevMob.start(mainActivity, REVMOB_APP_ID);
   }
   @Override
   public void showFullScreenAds(){
      revmob.showFullscreen(activity);
   }

   @Override
   public void openAdsLink(){
      revmob.openAdLink(activity, listener);
   }
}

Now, in the main Android class, create an instance of this class and pass it as an argument to the Game constructor:

public class MainActivity extends AndroidApplication {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();

      initialize(new Game(new RevMobDisplay(this)), cfg);
   }
}

Eclipse should warn you that there is an error with this modified code because the Game constructor does not expect this argument.So we will create a new constructor that expects this argument in your main project’s Game class (this is the Class that implements ApplicationListener)

public class Game implements ApplicationListener {
   ...
   public AdsDisplayInterface _adsDisplay;

   public Game(AdsDisplayInterface adsDisplay){
      _adsDisplay = adsDisplay;
   }

   public Game(){
      ...
   }

   @Override
      public void create() {
      ...
   }
}

Displaying Ads

Now, whenever you want to display a fullscreen ad, you can simply do the following:

if (_adsDisplay!=null){
   _adsDisplay.showFullScreenAds();
}

Remember we only created this class for the Android application, so if we tried to display ads from another platform, it would crash with a null pointer exception, so we check if it is null beforehand.

There you go, let me know if you have any questions in comments.

30 Second review of Cube Overlord on YouTube

Some time ago I contacted a YouTube reviewer for Cube Overlord and there is now a 30 seconds review available :)

While it’s quite short and doesn’t go into much detail about the different game modes, powerups … It presents the basis for this game quite clearly.

Since I haven’t managed to do any video/trailer for my game, it’s a good start if you wanna check it out!

Scoring System – Balancing and Handling difficulty

It’s been quite some time since I have posted! What have I been up to ?

  • I’ve updated my first game: Cube Overlord for Android.
  • I am waiting for libgdx free iOS publishing solution to come out of beta so I can start publishing on iOS too.
  • And….I’ve started working on a new Game !

My first game was a vertical scroller, I am happy that I did and released it. I am mostly happy about the results but it took quite some time and there are a lot of parts I am not so happy about. For my second game I want a simpler project where I can focus on those parts to improve my skills, so I am going for a puzzle game!

It doesn’t have a name yet but it’s going to be some sort of mix between Boogle and Tetris . The basis is quite simple you combine letters to make words and earn points.

I don’t have much to show yet, but I want to talk about the scoring system.

Most, if not all games nowadays have some kind of scoring system. You get 1, 2, 3…stars at the end of each level (I will refer to this as the “Star” system for the rest of this post), awards, achievements…

Cube Overlord - 3 Stars

Cube Overlord – 3 Stars

The Star System

The logic behind this is that it gives the players more goals to achieve and awards to collect, adding to the replayability of your game. Some players will be satisfied simply completing a level, but other want to beat the game 100% and get all 3 stars for each level. It’s usually good to cater to all kind of players.

Here I am not going to discuss whether or not this is a good idea but I want to talk about how I implemented and balanced this Scoring System in my new game, specifically how I designed my “Star” system

First, let’s talk about the possible criteria for this system:

Point based:

You get a star after you pass a certain threshold. The way the user collect those points is specific to your game and can vary in difficulty

Checkpoint based:

You get a star for a specific action or for filling a specific game condition in the level, there are many possibilities and of course most will be specific to your game. Here are some examples :

  • Finish the level under x seconds
  • Finish the level without getting hit more than x times
  • Collect one or several special/hidden items

This is usually a good idea when you want your users to experience your game in a different ways, explore the level instead of rushing to the exit (or vice versa), play stealthy rather than rush into the battle etc…

All is one

You might be tempted to convert those conditions into points as well:

  • The remaining time is converted into points,
  • The player looses points when  he gets hit
  • Special items gives a set amount of points.

but there are several drawbacks to this method

  1. If there are several ways to earn points, you loose the ability to “orient” the user toward a specific action/gameplay. Which is not a bad thing by itself depending on what kind of game you are going for. Leaving multiple options to earn stars means that you can play the way you want and not be punished, of course this work only if you have viable gameplay alternatives.
  2. You risk complicating the scoring system and making it too opaque for your player.

Examples

Cube Overlord

Most games will base their scoring system on points only or on a mix between points and checkpoint. Here is what I did for Cube Overlord:

  1. A star for completing the level (minimum required)
  2. A star when getting more than X points
  3. A star if you completed the level without being hit a set number of times (0 for harder levels)

What does this achieve ? Well in Cube Overlord, there is a mechanic to increase your score multiplier but it requires you to stay in the same color for long period of times, this create a whole new sets of challenges for the player that I will not detail here. If the player only wants to complete the level, then he can play it safe, but if he wants to get this extra star, he will have to use this “optional” game mechanic and engage in this new gameplay.

In this game, I play tested each level several times and estimated the point threshold to get this star based on my own scores. This was quite time consuming and required me to retest each level after a redesign. I didn’t want to make the same mistake this time so I looked into other solutions. (I am not saying you shouldn’t play test your game!).

My new project

For my new game, I decided to base my scoring system solely on points. This is a decision that you have to make on a case to case basis. For me it was quite straightforward, in my game you will get more points by making longer words. There is no reason to add extra incentives such as “Make a 6 letters word to get a star” and since there is already a time based game mode planned I didn’t want to add a time based condition such as “Get X words under Y seconds”. There is nothing stopping me from adding those as Challenges/Awards later on anyway.

Using a point system has the extra advantage that it is easier to decide the thresholds value for each extra stars using a systematic approach:

Warning: The numbers used below are used for this example and may not apply in reality, but the logic remain true.

I have the following point system:

  • 2 letters word : 15  points
  • 3 letters word : 30 points
  • 4 letters word : 50 points
  • 5 letters word : 75 points
  • 6 letters word : 105 points

It’s not linear because the difficulty to find longer words increases exponentially so the point system reflects that.

This is not set in stone but we will use this as a base, I evaluate the difficulty for each possibility:

  • 2 letters word : Very easy
  • 3 letters word : Easy
  • 4 letters word : Medium
  • 5 letters word  : Hard
  • 6 letters word: Very hard

First solution

Let’s say I want my first level to be very easy, and I want it to last about 30 seconds, I evaluate it takes the average user about 3 seconds to make a 2 letters words. So to make the level last 30 seconds, the user will be limited to 10 words (10*3 = 30, my math checks out!). So the target for my first level would be 150 points!

Now I want my players to be able to over achieve and earn extra stars,

  • so for one extra star the difficulty should go from “very easy” to “easy”
  • and for two extra stars it should go up to “medium”.

Let’s say it takes 5 seconds for a player to make a 3 letters word, and 7 seconds for a 4 letter words.

  • So for a 30 second game session, the first extra star will require (30/5 * 30 pts) = 180 points
  • And the second extra star will require (30/7 * 50 pts) = 214

This is not perfect of course, in this case I think I should increase the score for each extra letter, but it’s a good start.

Second solution (not necessary incompatible with the first one)

Let’s say I don’t want players to keep entering words after they get the minimum numbers of points required to finish the level.

Using the numbers from the previous solution:

  • If the user skills correspond to the “very easy” difficulty level, then he will finish the level (150 points required) when he uses up his last move.
  • If the user skills correspond to the “easy” difficulty level (3 letters words), then he will reach 150 points after (150/30) 5 moves, with 5 moves lefts.
  • If the user skills correspond to the “medium” difficulty level (4 letters words), then he will reach 150 points after (150/50) 3 moves, with 7 moves left.

With this information, I can give each moves a set number of points (20 for example), and set the threshold for each star accordingly.

  • Second star : 5 stars left * 20 points = 100 points. Threshold is at 150 + 100 = 250 points
  • Third star : 7 stars left * 20 points = 140 points. Threshold is at 150 + 140 = 290 points

Of course, players will find words of different lengths during the same play session but this even out in average and you should still get a star corresponding to your skill level.

Following this system, it should be quite easy to establish a scoring system adapted to your game. You will need to tweak your numbers for other factors (for example take into account added difficulty in the level design).

Cube Overlord – New game mode

After some small updates on my android game Cube Overlord, I am now releasing a new game mode! Time Trial.

Before I tell you how it works, here is a little back story of how it came to exist :)

Game modes

There are currently two game modes in Cube Overlord.

  • Stage/Story mode (with 10 levels)
  • Arcade mode (infinite vertical scroller)

For those that haven’t played it, it’s quite straightforward: You avoid cubes of the opposite color (you loose a life if you get hit) and you collect cubes of your color to gain points/beat the boss. And you can switch color anytime by tapping on the screen.

In Stage/Story mode you face a boss at the end of each level and you get 1-3 stars depending on your results.

in Arcade mode you are in a infinite scroller with increasing difficulty and try to get as much points as possible before you loose all your life.

normal-50

I also had another mode available during development, called Survival mode, it was supposed to work like this:

You try to survive for as long as possible, game speed increase every second until you reach terminal velocity. Cubes pattern become more and more complicated. There are no power ups and no extra life. Score is determined by how long you manage to stay alive. Quite simple if you ask me :)

But there were several issues with this game mode and in the end I wasn’t very happy about it:

  1. There wasn’t any incentive to collect any cubes, a very big feature of the game therefore became useless in this mode. I consider this as a failed design. The mode would have been functional but it wouldn’t make much sense. It would actually punish players trying to collect cubes as it would make it harder for them for absolutely no benefit. It was counter intuitive and it didn’t fit with the other game modes.
  2. I could have made it so that collecting cubes would also bring you points, but I felt this would be too similar to the current Arcade mode and didn’t warrant a game mode of its own.

After musing it over, I finally decided to scrap this mode entirely and release it like that. This allowed me to focus on other things and not delay the release of my game. I justified this by telling myself I would keep on working on this mode after the release and eventually make it available in a later version.

So after the game got released, I started thinking about this mode again, trying to find a way to make this work. And this is how I ended up with the Time Trial mode.

Design

Here is how the design process went:

I started from the issue at hand: Collecting cube in this game mode is useless.

Possible solutions:

  • Gain points -> Already rejected before
  • Change Survival mode to a mode with limited time -> you no longer try to survive for as long as possible, but you have 60 seconds to go as far as possible

Sounds good, now increasing the time left when collecting blocks actually make sense. This fixes the issue at hand.

Let’s try this! I make small modifications to the survival mode:

You have 60 seconds, each cube you collect adds 1 second, getting hit removes 10 seconds, as before, speed and difficulty increases as time passes. You can get time multiplier by chaining 10/20/40 cubes of the same color.

How it plays:

It works, but it’s too easy to collect cubes, I never run out of time and always end up dying by getting hit several times in a row once the game reach a certain difficulty level. Similar to what’s currently happening in Arcade mode.

Possible solution:

It should be quite easy, try to tweak the numbers. On my first try I basically divided by 2 the time added when collecting cubes.

How it plays:

It’s still too easy, and now you have a “+0.5” showing up on screen each time you collect a cube. Ugly. I don’t want to show a bunch of decimal numbers on screen, it’s confusing.

Before trying to tweak the numbers again (+0.33 ?), I try to get the root cause of this issue.

My conclusion: As difficulty increase, you have more cubes on screen and as speed increase you can collect them even faster. I will not be able to find a number that will be balanced for all difficulties unless it also varies with difficulty. This is starting to get complicated and I don’t want to confuse the player.

Possible Fix:

  • Don’t increase the speed as time passes and/or have less cube in harder difficulties -> I didn’t even try it as I knew it would make the game too boring. Many peoples complained that the first levels of story mode were too slow, and I wasn’t going to do the same mistake again. Anyway this would kill the sense of progression.
  • Add special cubes that show up every X seconds to increase your time -> Back to square one, what’s the point of regular cubes then ?
  • Instead of adding extra time when you collect cubes, increase the player speed! So he can travel further -> Sounds about right, let’s try this.

It works fine, some tuning, are necessary but this solution is quite balanced: It is necessary to collect cubes to go further/faster but it also increases the difficulty as it makes it harder to dodges cubes now

Final solution

You have 60 seconds to go as far as possible, collecting cubes of your color increase your speed (you fill up the bar at the bottom of the screen), collecting power ups give you some  extra time (~4 sec) and getting hit makes you loose 10 seconds and half of your increased speed !

This is probably not perfect but should work quite well, I will obviously tweak things as I get some feedback, but I am quite happy with what I ended up with.

First Update to Cube Overlord

This is the first time since the game has been released that I have had enough time to work on it.

Listening to some feedback by players, I implemented the following:

  1. Dying animation: you no longer go straight to the game over screen when you die, the game slow down and your cube fall off the bottom of the screen, only then the GameOver screen shows up. That was much easier that I thought it would be to implement, but it still took quite some time.
  2. Replaced the confusing multi colored cube animation that lets you grow by a a “heart” PowerUp, hopefully it is now obvious that it is a positive thing to pick up :)
  3. Added two new Awards (and ingame “awards unlocked” animation)
  4. Slightly increased the speed of the first levels.
  5. Better UI for android tablets

Otherwise I am working on a Time Trial mode. Hopefully available soon.

You can get the new version here!

Android app on Google Play