• Register

An Island survival sandbox game. Build up your resources, build your shelter, fish and hunt for food and just stay alive. Early development, missions/achievements/story to come later.

Image RSS Feed Latest Screens
New Adventurer! New menu system being developed Fish Spawner on full power
Blog RSS Feed Report abuse Latest News: Parse.com Restful API in LibGDX Game

0 comments by carelesslabs on Jan 9th, 2014

To have a break from fish AI, this evening decided to set up a highscore board feature as a test case for JSON and online storage for Endure. There are many companies offering this sort of service to game/app developers but I have heard good things about Parse so thought I would try them first.

So I 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, SDK's and sample projects so you can hit the ground running.

The best thing is the price... free!

Features

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

There are paid plans available but while in development phase this is perfect.

Scores Table
After creating a new app I created a new class named 'score', using the simple GUI added score and user to the table:

I did try out the Android sample project but without your app being Android as expected there was no way to use the .Jar libraries that Parse provide, but they do offer a great Restful API to POST and GET your data. The website is clean and very clear:


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. Connects via HTTPS using an app id and key, so make sure you hide your code before putting it out there.

LibGDX has its own Net library so I also gave this a go as my code looked messy, this too was simple to get working, I 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, 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 on data requests, Parse provides many different keys and you have to set and use the right ones depending how you are connecting. 

Full Source Code (My Parse Class)

Here I called the class as soon as the game started, a hard coded score is pushed to the 'score' table and then all scores are returned:

Lots of testing left to do with this and of course will need to ask/store the username (@twitter_tag) of the current player. I 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 (containing username and score) and also parse the results into objects so they can be displayed in game.

Thanks for reading.

Media RSS Feed Latest Video
Post comment Comments
FahriAuditore
FahriAuditore Feb 26 2014, 12:51am says:

Looking up for this!! And hope there is a co-op or multiplayer LAN :D

+1 vote     reply to comment
carelesslabs
carelesslabs Apr 2 2014, 5:15am replied:

Thanks for checking it out, have lots of plans for this, as I just commented below I have another project to run with for a while but this is the game is most want to complete. @carelesslabs on twitter if your interested.

+1 vote     reply to comment
TKAzA
TKAzA Jan 6 2014, 8:28am says:

Loving the simple tile art, looking forward to seeing the crafting system inplace, tracking.

+3 votes     reply to comment
carelesslabs
carelesslabs Apr 2 2014, 5:13am replied:

Thanks, I would like to get a demo out soon, as a one man team and two projects open at the moment I am a bit delayed with this one. Have big plans for it though

+1 vote     reply to comment
carelesslabs
carelesslabs Jan 7 2014, 8:20am replied:

Thanks, the crafting system is in place right now, but there is only one recipe. It follows MC style crafting but I would like to expand on it later. I will add a few basic items and put an article up on crafting soon and look forward to feedback on it.

+1 vote     reply to comment
Leanardoe
Leanardoe Jan 6 2014, 12:31am says:

What is this game programmed in?

+1 vote     reply to comment
carelesslabs
carelesslabs Jan 6 2014, 6:55am replied:

Java using LibGDX & Box2D Lights

+2 votes     reply to comment
Guest
Guest Dec 24 2013, 7:53am says:

This comment is currently awaiting admin approval, join now to view.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Icon
Endure
Platforms
Windows, Mac, Linux
Developed By
carelesslabs
Engine
libgdx
Contact
Send Message
Release Date
TBD
Game Watch
Track this game
Share
Style
Genre
Adventure
Theme
Fantasy
Players
Single Player
Project
Indie
Boxshot
Boxshot
Embed Buttons

Promote Endure on your homepage or blog by selecting a button and using the HTML code provided (more).

Endure
Endure
Statistics
Rank
2,449 of 16,124
Last Update
1 month ago
Watchers
20 members
News
4