Skip to content

Configure Your Game – Configuration Files Made Easy by Play!

This Post is simply making a statement about the usefulness and simplicity of Typesafe Config Library within Play! I used it because I needed to balance my Monsters’ strengths. Things like health, offense, damage and defense should be configurable and best be very distinct from Monster to Monster.

What would be easier than having them quickly available in a config file rather than in DB? For tweaking and testing this is enough and it keeps me going.

You can do that quite easy too:

  1. Put a the file into your Play /conf folder, named yourname.conf
  2. Load the file using the name:
  3. Access the config file properties via


Here is how I proceeded loading the Werwolf properties from the werwolf.conf document into the corresponding Java class:



Have fun configuring!




Play! And Hibernate – How To Get Running With Your JSON REST API

Now that our resources are planned let’s quickly set up Play! for persistence. I don’t like configuration… it kicks me out of my workflow and makes me thinking if to continue my work because the next step would be… yeah… configuring something.

Nevertheless with Play it is not that bad and done really quick. You will be able to persist Java classes to a in-memory H2 database using JPA.


Play! And Hibernate – How To Get Running With Your JSON REST API

At some point you need some persistence. In my case, I need a central online place for all the Monsters my players will create and fight with. I need them centrally managed instead of locally on their devices.

My very intuitive approach was to make the information available via a REST API.

Here is how I did it. Setting it up on Play! is as easy as the name indicates.

If you are new to Play!, don’t worry I will also cover the configuration part in this series.

Resource Planning

Important enough when you want to design a REST API is the question “What kind of Resources do I need?”. Even when you only need a simple API for testing it is a good training to actually put some thought into it. As a best practice rule there are two kinds of resources you should model out: (Continued)

How To Build An Cocos2d iOS App Communicating With A RESTful API – The Sequence


iOS 7 is out and therefore SpriteKit. This means I will add to this series the same solution using SpriteKit. I am really curious how much work it will be using it. But at first let me describe the next step in our cocos2d implementation.

I already explained some of my code in the other posts of this series, so that we can make this round now. Let’s see how we can finally retrieve information from an WebAPI and render them for the user as soon as the information returns.

What I didn’t describe so far is my model. My model class is the BaseMonster class that contains a list of monster attributes. Such as its health, strength, offensive value… you understand. The thing is that this information live on the server and are accessible via the Web API.

Let me go over the sequence diagram here to me it clear again.

iOS and REST Http Requests


Objective-C Adapter From NSInteger To id When Using performSelector withObject

As an Objective-C beginner it is not so easy to understand how to correctly cast things, so I needed some research to get it solved. I hope that post makes it easier for you. My problem occurred trying to feed the performSelector withObject message with an enum.

I implemented my nice HTTP Request class, which I will explain in the next Posts completely. So, everything worked well as long as my web server was reachable… so I thought, adding error handling should be easy too. But there was some small complication.

What I planned to do was: Whenever a HTTP communication error occurs, I don’t wanted to give up, but I wanted my request to be rescheduled. This way I could retry for a while having the chance to successfully process the request in case the web server becomes available again.


How To Build An Cocos2d iOS App Communicating With A RESTful API – The View

Let us start with the view part of our REST web service integration to iOS and Cocos2d. Actually, I want to provide the same solution with Sprite Kit once I finished this series. But first things first.

The Background Layer

So, first of all we need a layer for our game. The layer is the component that takes our views. My layer is named CombatUILayer and is a subclass of CCLayer.

Here is the header:

What you will recognise is that I use a TiledMap fightScreen that actually contains a set of objects (textfields) that I populate with the values retrieved from the web interface. Here is how this looks in Tiled. Awesome tool for tiled maps by the way and absolutely beginner friendly.

FightScreen image with objects


Cocos2d for iPhone or Apple Sprite Kit?

Ok, it took me some weeks, even months of effort to feel comfortable with Cocos2d and Objective-C and at least have starting points to solve all requirements that might cross my way.

After reading an eye-opening post from Steffen Itterheim here I will rethink my approach using Cocos2d in favour of SpriteKit. It might take me a while to recap some concepts and I loose iOS 5 & 6 support.

But all this could pay off using a native game development engine even though some of my learning effort is wasted.


How To Build An Cocos2d iOS App Communicating With A RESTful API – Intro

I want to start a series on a topic that was not too hard to get together but resources were quite distributed and some rocks were in my way as an Objective-C newbie.

I want to show how you can render JSON information retrieved via REST web services. The following picture Combat Screen shows an example.


Combat Screen

Yes, it doesn’t look perfect at all but I don’t want to show my design skills. What you see in the pic is pretty obvious I hope. In its final version it should show a combat screen allowing an offensive Monster to attack a dungeon that is going to be defended from the right hand side Monster. On the left side are the offenders attributes and on the right side are the defenders attributes. All information of that monsters reside on the web app that we can request via our Web API. How to build up the Web API with Play! I will discuss in another post – for now just let’s assume there is something like http://localhost/playerId/monsters/monster/id. We can use HTTP GET to obtain information via that URL.

I think it makes sense to split this how-to into smaller pieces freely following the divide and conquer principle. The figure below shows the whole picture I want to explain.


Class Overview

  1. When invoked/clicked by the user the CombatUILayer : CCLayer component initiates two MonsterView : CCNode classes that should be rendered – one for the attacking monster in view and one for the defending
  2. First, the MonsterController : NSObject creates the MonsterView object requested by the CombatUILayer
  3. Second, the BaseMonster : NSObject class invokes an asynchronous HTTP request to our Web API given a Block code that will be invoked when the HTTP request returns (either successful or not)
  4. The HttpRequest class that defines all need methods to implement the needed HTTP protocol. It is given the Block code we defined in the BaseMonster class.
  5. The defined Block code being invoked when the asynchronous HTTP request returned will update the CombatUILayer to actually draw the retrieved information.

The following posts will detail code of the View, Model and Controller part of the solution from an iOS perspective.

Yet Another Game Development Blog?

I am starting this blog to share my experiences with developing an iOS app that communicates with a Play! based web application. The app I want to build is called Kerkermeister (which is pretty close to the english version of a dungeon keeper). Inspired by role-playing and strategy games I want to build an app that I would have fun with. I like a lot of apps on the app store but I am pretty much bored of Tower Defense already and Clash Of Clans is somewhat too expensive.

I want to mix ideas from genetic algorithms and a role-playing based combat engine. The downside is: Except of a good experience in playing games I am completely new in game development. Design is the area I need to learn most, but I am planning to request some help on this.

Also, I am completely new in cocos2d and Objective-C and on some points I got headaches when it comes to Blocks or Delegates.

I am focussing on the following technologies:

There are a lot and mostly good quality resources on certain issues. My problem often is, that solutions are written from a point of view that doesn’t match mine or my experience. I want to contribute another point of view that might be helpful for people starting on this topic, just like me.

The things that helped me starting with Game Development on iOS is Kobold2D. A really great framework used in conjunction with the book of the framework’s author Steffen Itterheimer. I don’t know this guy so my praise is honest. Here is the link to the book I recommend starting with.

And Play!? Easy to use and fun. Either you like Scala or Java, both is possible and a new Play! app is running in 5 minutes thanks to Convention over Configuration. I like how it feels and the REST approach it offers makes it a perfect candidate for a backend service that will be designed API-first.