Thursday 9 January 2014

LibGDX and Parse.com

To have a break from fish this evening decided to set up a highscore board as a test case for JSON and online storage for Endure.

Full Source Code

Signed up for Parse.com a very neat data-store for mobiles and web applications, they provide example projects for JavaScript, Unity, Android and other platforms.

The best thing is the price... free!

Features
  • Requests: 1 million/month
  • Pushes: 1 million/month
  • Burst Limit: 20/second
 Scores Table


 I did try out the Android sample project but without your app being Andriod as expected there was no way to use the .Jar libraries that Parse provide, but they do offer a great Restful method to POST and GET your data.



Custom Parse Class

I wrote a very simple Java class and imported Java's own Net and IO libraries did not take long to get some scores in and out of the service.

LibGDX has its own Net library so I also gave this a go as my code looked messy, have some speed tests to run yet but happy to be able to push and pull data for free and with no real hassle.

I will not go through my code put post the class for you to see, the important lines here are:

httpPost.setHeader("X-Parse-Application-Id", app_id);
httpPost.setHeader("X-Parse-REST-API-Key", app_key);

conn.setRequestProperty("X-Parse-Application-Id", app_id);
conn.setRequestProperty("X-Parse-REST-API-Key", app_key);


While looking how others use Parse with Java I saw a lot of complaints about unauthorized errors, Parse provides many different keys and you have to set and use the right ones. 

Full Source Code

Code adding hard coded score and retrieving all scores


Lots of testing left to do with this and of course will need to ask the user their name (@twitter_tag) when they start the game, will use this for the upcoming fishing competition and keep a track of all the fish caught.

Also will need to use a JSON library to properly generate the string that is post and also parse the results into objects.

Thanks for reading.

2 comments:

  1. The Parse stage gives a complete backend answer for your versatile application. Our objective is to completely wipe out the requirement for composing server code or keeping up servers.

    ReplyDelete