Saturday, 19 April 2014

LibGdx Google Mobile Ads SDK Tutorial

The number one ad service being used by Android and LibGdx developers at the moment is Google AdMob.

If you've not updated your app recently you should consider doing so soon. Google says:

Android (6.4.1 and earlier SDKs)
Deprecated. On August 1, 2014, Google Play will stop accepting new or updated apps that use the old standalone Google Mobile Ads SDK v6.4.1 or lower. You must upgrade to the Google Play version of the Mobile Ads SDK by then.

Ok, so we want to migrate to the new Google Play Services way of doing things - this blog post walks you through the process :)

Install this apk to see what we'll be building!

----------

Barebones Sample App

First thing I did was grab an up to date version of libgdx. They are now up to 0.9.9 stable, I'm sure there is a lot of awesome new stuff in there for me to investigate, but TheInvaderOne isn't really leaving me with a lot of time for Android these days so that'll have to wait!

Next I created a new libgdx project using gdx-setup-ui.jar (see this old post for a walkthrough), added a .gitignore file, and made my initial commit.


Eclipse Setup

In eclipse, import the barebones sample app (file > import > existing projects into workspace) - you should now have at least three projects in package explorer (core, android, and desktop).

Open the Android SDK Manager, download the latest SDK Platform and Google APIs (at time of writing: 4.4.2/API19), the 2.3.1/API9 SDK Platform, and from Extras - Google Play Services.

Locate the <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/ directory on your machine (on my windows machine - C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib) and copy into your working directory alongside the existing libgdx projects.

File > Import > Android > Existing Android Code, Next, Browse, navigate to the local copy of google-play-services_lib in your working directory, Ok, Finish.

Right-click your android project, select Properties, Android, scroll down and click Add, select the google-play-services_lib project, Ok.

A refresh and clean in eclipse probably wouldn't hurt at this point, so go ahead and do that.


AndroidManifest.xml

Ensure that the target in android project's project.properties file is at least 13, and the android:minSdkVersion in your AndroidManifest.xml is at least 9. Sadly this does mean users running ancient versions of Android will be excluded, but there's nothing we can do about this. There are very very VERY few devices still running versions below 2.3/API9, so at least you won't be excluding many users...

Add these two lines as children of the 'application' element:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/><activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Add these two permissions as children of the 'manifest' element:
<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Save changes, then refresh and clean in eclipse for good luck...


Banner Ad

See this version of the android project's MainActivity class for a reasonably straightforward banner ad implementation.


Interstitial Ad

This diff shows an interstitial ad implementation (ActionResolver interface lets us trigger interstitial actions from the core project while retaining the invaluable LibGdx cross-platform functionality).

----------

That's all there is to it!

As always, please feel free to leave comments below. I can't really offer support - TheInvaderOne and "Real Life Day Job" leave me very little free time these days, but other visitors will often leave helpful solutions, and if I find a spare moment every now and then I do try to answer any unresolved queries.

Anyway, I hope you have fun making your games - be sure to leave a note here if you release something on google play or the amazon market, I'm always happy to check out new games :)

PS - one final note if cloning from https://github.com/TheInvader360/tutorial-libgdx-google-ads, pay attention to the problems view in eclipse! You will need to create an empty 'gen' directory in both the google-play-services_lib and tutorial-libgdx-google-ads-android projects, and ensure you have the required android sdks installed. As is often the case with eclipse, a liberal amount of refreshing and cleaning will do no harm...

Sunday, 9 February 2014

Back with a new game - Little Fish

I've been away from the world of Android Games for a little while, but I do have a couple of good excuses:

  1. My role has changed at work and I am now a developer - this is pretty awesome. Ok so it's dry databases and stuff, not games, but I'm getting paid to do what I enjoy, and am feeling pretty good about that! It does mean more of my spare time being spent on work related learning though, so a little less time for Android Game development.
  2. Even bigger news than career change... We're expecting our first baby!!! TheInvaderOne should be delivered by the stork at the end of next month :-o Preparing for the arrival of a human worm baby takes up a lot of time, though of course nowhere near as much time as once she has actually arrived. Spending time with her will be way higher up the list of priorities than playing with Android, so I either need to drop my hobby, or make it more efficient...

What I have been doing over the past few months (as and when I found a few spare hours here and there) is working on a sort of 'white label' app built on top of LibGdx. It includes a lot of the dull and boring to implement stuff that I end up doing over an over again, highscores, user preferences, ads, facebook integration, google play game services integration, splash screen, etc. In theory I will be able to use this as a quick start platform to speed up the game production process in future. I don't currently have plans to open source this as it's a bit too closely tied to my own stuff, and decoupling would take valuable time that could be better spent making games, but maybe sometime in the future it'll be an option.

I'm hoping that this quick start platform will allow me to continue making Android Games even after baby has arrived. The recent success of Flappy Bird proves that a game doesn't have to be sophisticated to become a runaway success. At its core it's a simple game (basically a reskinned helicopter game), with simple graphics. I'm sure the developer wouldn't mind me saying a similar game could be built in a single weekend, especially when leveraging a quick start platform. I've had some success in the past with my Racing Game and Quack Attack that proves the same point, simple/fun/addictive beats complicated/polished/boring. So, in future I can focus more on game mechanics and less on the surrounding app furniture, this can only be a good thing :)

I've just published my first game that makes use of the white label quick start sausage machine (catchy name) "Little Fish". The gameplay is pretty simple - you control a little fish that eats smaller fish. Bigger fish will eat your little fish, so avoid them! There's the added complication of poison fish that you must avoid at all costs (even if they're tiny). Once you've eaten enough little fishies (empty hunger meter), you progress to the next level where you'll be a bit bigger. Of course the screen is no bigger, so dodging the predators will get harder the more you progress! Simple game, but fun and addictive :)


I've added a couple of new features to Little Fish too. First there's a kids mode, there are no gameovers in this mode (unless you choose to quit) the tradeoff being no global leaderboard score submission. I've seen lots of little children want to play mobile and tablet games recently, but when they are very small it can be frustrating losing quickly, the kids mode will help keep them happy and occupied for longer. It can also double as a training mode, once the child has mastered the more forgiving kids mode, they can try the more challenging normal mode! The other new feature is extended controller support. Not only can you choose to control the Little Fish by touch or tilt, you can also use the dpad of an xperia play (and hopefully any other android device that has a control pad) or a HID compliant external controller. The guys over at Moga recently sent me some awesome free stuff, and it was an absolute breeze to get Little Fish working with the Moga in HID mode. When I've had time to play with the Moga SDK properly I expect I'll write a blog post dedicated to that.


I hope you'll check out Little Fish and of course all my other games. As always, I hope you have fun!

Saturday, 19 October 2013

LibGDX Google Play Game Services Tutorial


Google Play Game Services offers cross platform social leaderboards, achievements, and much more (realtime multiplayer, cloud saves, anti-piracy...). I've started implementing google play game services leaderboards and achievements in my LibGDX Android Games, and the purpose of this blog article is to walk through the process so you can do the same!

  • I've published an example project on Google Play check it out!
  • The example project is freely available on GitHub check that out too!
  • You can also get the complete (free) version of Super Jump a Doodle here!

Continue reading after the jump to find out how to add these features to your own games!


Monday, 10 June 2013

One million installs!


1,066,345+ users have installed my LibGDX Android games :)

Due to reporting lag that number is a few days out of date, and it doesn't include installs from third party scraper style stores, so the real number will be a little higher, but I can safely say I have over a million installs in total. Awesome :)

So, how do the various markets stack up?

Sunday, 26 May 2013

Street Race Swipe LibGDX Scene2D Tutorial



I have been meaning to write a LibGDX Scene2D tutorial for some time now (ever since my Quack Attack FREE Duck Hunt Game got ridiculously popular). The problem has been finding the time, instead of writing blog entries I've been making games!

I had a great idea for a multitasking game, play four independent games at one time to train your brain and test your ability to multitask. The result was my 4 Games 1 Screen FREE Brain Training Game. I built this game as four separate games from the outset, with the intention of possibly building further on each minigame and releasing as standalone apps. The first of these standalone apps is Street Race Swipe Racing Game, which brings us neatly to the point of this article...


Street Race Swipe Racing Game is such a simple game at its heart that it seems like an excellent candidate for a tutorial article :) I remember being massively impressed by the example SimpleApp on the LibGDX wiki when first starting out, there was so little to it but it touched on all the basics of what is needed to make a game. I'm hoping this mini project will be almost as simple and just as helpful to others!

Wednesday, 15 May 2013

4 Games 1 Screen - Musings on mobile game control



So often I hear that players hate onscreen controls on touch devices. No physical button means no tactile feedback to let you know you are 'touching but not pressing' a button. This fundamentally different interface means the traditional joystick / d-pad control scheme can no longer be the de facto standard for gaming controls across all platforms - replicating "up down left right a b start" on a phone or tablet is far from ideal (but an ouya or gamestick is another matter entirely ;)).

In my latest game, 4 Games 1 Screen, I try to make the most of a tricky situation. I've embraced the android mobile platform and the control options it offers. Our phones and tablets have accelerometers and touchscreens, the old nintendo and sega machines did not, it's time to think outside the box and make the most of these features.

4 Games 1 Screen is a challenging brain training game, the aim is to multitask by playing four games at one time, and avoid making too many mistakes. Make too many mistakes and it's game over. Each game is kept relatively simple for two reasons - first the game has to have a single objective and control method, second you have to be able to play four of these things at once so too much complexity would be too distracting for the player.



The mini games are:

  • Asteroid Attack - Tilt to steer your ship, asteroid collisions damage the shields, and when the shields are gone - gameover man, gameover!
  • Tap Jump Cowboy - Classic infinite scroll platform game (like canabalt, and gemserk's excellent vampire runner) tap the screen to jump, save the cowboy from running into the campfires!
  • Speedy Sums Math Master - Fully engage the left side of the brain, evaluate the math problem and mark it as correct or incorrect... You not only lose a life when you get it wrong, but also when you run out of time - so think fast!
  • Street Race Swipe - Swipe up or down to change lanes in this fast and furious racing game, avoid crashing into the other sports cars, too many bumps and your car will explode!


Each game can be played independently (full screen) in practice mode, but the real aim of the game is to play them all at once - the game is called "4 Games 1 Screen" afterall :) I find it fun, addictive, frustrating and challenging. The frustration is what makes it so addictive haha, I see gameover and immediately try again to "do it right this time" :)

No onscreen controls, and a game that would not really be possible on traditional gaming platforms, this is truly a mobile game designed for mobile devices. I hope you go on to check it out (it's FREE, so why not!) and if you also like making your own mobile games that you might consider some of the thought behind the concept - don't lament the lack of physical controls, instead make the most of what is available!



Finally, does this mean that I won't ever release a mobile game with onscreen controls? No. Definitely not. A future project will be a traditional platformer, with android enabled consoles like the ouya and gamestick firmly in mind. I will no doubt make a mobile version of this game with onscreen controls (it would be silly not to). I'm not against onscreen controls, I'm against not thinking up interesting ways to make the most of what the mobile platform offers. I believe a platformer will only work well with traditional controls, but we don't always have to make traditional games :)

Happy gaming boys and girls!