Performance issues with Polygon Colliders

I am currently working on a little mobile 2D game and had a issue that almost drove me crazy. Some objects that were supposed to move across the screen at a constant speed where “stuttering”. I tried different approaches for the way I move the objects but nothing seemed to help.
At some point I started disabling almost everything in my scene and enabling it again one by one. As it turned out the polygon colliders 2D of some objects where really hurting the performance. If you assign a polygon collider to an object Unity will fit it automatically to the shape of the object and I guess most of the time it does a good job at that. In my case however Unity used around 300 points for the polygon collider of a rather simple sprite. Luckily you can edit the points yourself and I was able to recreate the collider using only 18 points and that solved all my performance and “stuttering” issues.

Ludum Dare 40 – Post Mortem

I recently joined the Ludum Dare game jam for the first time and since it seems to be almost mandatory I want to write a quick post mortem for my entry ‘Triangle Command’.

Ludum what?

Just in case you don’t know what Ludum Dare is about: It is an event that takes place every 3 months or so where everybody can join to create a game for a given theme. Ludum dare features two modes: the compo and the jam. The compo is the more strict version where you have 48 hours time, must work alone and can only use the stuff you make in those 48 hours (with some exceptions I believe).
The jam is more loose. You get 72 hours time, you can work in a team and you can reuse stuff you made prior to the event.

The idea

The theme for the event is selected in several “theme slaughter” rounds where everyone can vote for their favorite theme. In the end the theme for this Ludum Dare was ‘The more you have, the worse it is’.

48 hours (or 72 hours) is not really much to create a complete game and given the fact that humans have to sleep, eat and other stuff you got even less time. Due to real life obligations I figured that I could spend something like 8 hours maybe. So I needed something simple.

I came up with the idea of a side scroller with a very minimalistic design. Since I am not good at creating visuals for games, that minimalistic design approach was not really a choice – I just didn’t have any other option. So I created all of the “art” for my game within 10 minutes or so.

Here is a short gif showing my game:

So your task is to avoid the obstacles. You can collect the circles (‘energy pellets’) by shooting at them. This will make you faster and therefore make the game harder but it also increases your score faster. If you are going too fast, you can also dump an energy pellet.

Developing the game was pretty straight forward without running into any major problem. It took about 8 hours including graphics, programming, sound effects, music and publishing the game.


I didn’t expect my game to get high ratings but I have to admit that I was a bit disappointed when the results where available. Here are the ratings for my game:

Overall: 607th (2.78 average from 27 ratings)
Fun: 585th (2.7 average from 27 ratings)
Innovation: 608th (2.438 average from 26 ratings)
Theme: 379th (3.36 average from 27 ratings)
Graphics: 624th (2.28 average from 27 ratings)
Audio: 334th (2.917 average from 26 ratings)
Humor: 541st (1.765 average from 19 ratings)
Mood: 591st (2.341 average from 24 ratings)

In total there where 2890 submissions, so obviously I could have done much worse. And given the fact that I couldn’t put much time in it I am still somewhat satisfied.

Final thoughts

Being “forced” to create a game within such a small time frame was really interesting. You have to strip down your game to its minimal required features and you learn a lot about scoping I guess. Also in the end you created a complete game which is pretty cool I think.

I will try to join the next Ludum Dare and come up with something more innovative and more fun.


The project page contains everything related to this game.

Generative Adversarial Networks on Azure

Today I got something different. Instead of game development I want to talk about machine learning.

I recently stumbled across a tech demo by nvidia showcasing the generation of fake images using a Generative Adversarial Network (GAN):

nvidia gan

Just to give you a quick idea of what a GAN is:

A GAN consists of two neural networks, the ‘discriminator‘ and the ‘generator‘.
The discriminator receives real data (eg images) and learns that those images are real.
The generator on the other side produces fake data (eg fake images) and feeds them into the discriminator. So, the discriminator will try to distinguish between fake and real data.

Both neural networks learn over the course of the training. The discriminator gets better at telling real and fake data apart and the generator gets better at fooling the discriminator.
But eventually after enough training the generator will become so good that it is impossible for the discriminator to decide what is fake and what is real.

Since the computations needed are pretty complex they take a very long time when running on a CPU. Luckily you can use your GPU for that. For that to work you could use nvidias CUDA (if you own a supported nvidia graphics card) or you can setup a preconfigured Azure Virtual Machine.

Microsoft Azure features a template for deep learning virtual machines called the “Deep Learning Virtual Machine” (surprise). It has all the necessary stuff already installed like python and tensorflow (and a lot more) and is also configured to utilize the GPU for computation.

If you want to know more about GANs I highly recommend the following youtube video:
(Also, if you are interested in machine learning I recommend the whole channel).

So I wanted to give it a try and used the code provided in that youtube video. (Github)
The code is writte in python and uses Tensorflow as machine learning library. The original code tries to create new Pokemon based on the 150 (151?) original Pokemon but the result weren’t really satisfying:


So I tried something different. Instead of Pokemon the discriminator was now training on parts of the mnist set (a collection of handwritten digits often used as a simple example of image classification). In particular I only used the digit 4 and wanted to see if the generator would be able to produce something that looks like a 4. Here are the results:

Nothing to see yet..

After 10 iterations you can make out something that could become a 4.

After 20 iterations you can see some almost perfect 4’s along with some images that look like a 9 or maybe even an ‘A’.

Strangely after that it got worse again:

Iteration 30

Iteration 40

Iteration 50

So at that point I stopped with the mnist data set. I am currently trying to create images of me but I actually expect something like the generated “Pokemon” instead of actual faces.

That’s it for now. If my GAN actually produces something that looks like a face I will let you know.

Quickies – Breakout

About and brief history

In Breakout the player controls a paddle to shoot a ball at bricks which are then destroyed. Depending on the clone/version you play there might be bricks with different colors, powerups etc. It is sometimes considered to be a bit like a singleplayer Pong.

Breakout was created in 1976 by Atari. The creation of the game involved big names like Steve Wozniak and Steve Jobs and the whole story is quite interesting. You should read it: wikipedia

The game was officially ported to several systems and countless unofficial clones exist – like this one 🙂
You surely also know Arkanoid which is one of the more well known clones or “expansions” of the original Breakout.


Since there are so many different versions of the game I had to do some planning on the features I wanted (to be honest I decided about features during development but I will act as if I did proper planning):

  • Diffent Bricks (with different numbers of hits it takes to destroy them)
  • PowerUps and PowerDowns
  • A design-time level editor
  • Multiple levels
  • A somewhat realistically moving ball

Breakout was somewhat more complex than the previous Snake and it’s interesting how many bugs you can have in such simple game.
As you can see I again used this cool art style called “Programmer art”:



Custom Editor
As stated above I wanted to have a level editor but actually it wasn’t about having that editor – it was about getting into unity editor scripting.
Just to make that clear: This editor is not for the player but for the developer to be used inside unity. I will not talk much about the editor itself but more about how to get something like this started (check out the source code on the project page for implementation details).

Ok, so we want to create levels and we want them to be persisted. We could use something like a text file but we would need to handle saving and loading of our data. Luckily there are Scriptable objects in unity. Scriptable objects are scripts that can be saved and used as an asset and they are automatically persisted as long as everything we put into them is serializable.

Lets have a look at our Level class first.

public class Level
    public string name;
    public int width;
    public int height;
    public int levelIndex;
    public int[] levelStructure;
//details omitted

The levelStructure array holds the information about the level. A 0 means no block, a 1 means a 1 hp block and so on. You may wonder why I used a one dimensional array instead of a more suitable two dimensional array. This is because unity can not serialize multi dimensional arrays but it can serialize one dimensional ones.

Our scriptable object derives from ScriptableObject and only contains a list of (serializable) levels.

public class LevelsSO : ScriptableObject {
    public List<Level> levels;

Important: It is not so obvious how to save the scriptable object as an asset. To do this we annotate the class with the [CreateAssetMenu()] Attribute. Now inside the project tab (where your scripts, assets etc are) we can right click, chose ‘Create’ and at the top of the list we got our ScriptableObject. Click on that and you got the asset. When you select it you will get the unity default inspector which is not very convenient to actually create levels. Thats why we create a custom Editor.

For that we create a class that derives from EditorWindow.

Inside this class I created the following function which handles the creation of a new EditorWindow.

public class LevelEditor : EditorWindow
    public LevelsSO levels;

    private Level selectedLevel;

    [MenuItem("Custom/Level Editor")]
    public static void Init()
        LevelEditor editor = EditorWindow.GetWindow<LevelEditor>("Level Editor");
        editor.minSize = new Vector2(800, 600);

    void OnGUI()

The annotation above the Init() function tells unity to create a new menu item called “Custom” with a child element called “Level Editor”. When you click this in unity the Init() function gets executed.
The LevelEditor class also holds a reference to the scriptableObject asset so that it can save to and load from the asset.

The drawing of the actual level editor happens inside the OnGui() method.

The rest of the editor are simple gui controls, mainly buttons. I will not go into detail here. You can have a look at the source code if you want to know the details.

Level editor
Level editor


There are still some things to do (besides the terrible graphics) but I wanted to move on to the next project.
So for example it would be nice to have some sort of message about powerups/powerdowns. A more serious problem is that the ball can get “glued” to the left or right boundaries and it needs some serious breakout skills to get it off those walls. Additional sounds would have been nice (I’m sure you noticed the awesome ‘beep’ when you destroy a brick and the incredible soundtrack – special thanks to my good friend DJEJ for that track.). The editor is in a very raw state and could use some polish. And so on…


The project page contains everything related to this game. It includes a playable WebGL version as well as a downloadable version for windows. The source code is also provided and can be downloaded.

That’s it for this quickie. Stay tuned for the next one!

Quickies – Introduction & Snake

About Quickies

Quickies are little game projects (usually clones of classic games) I mainly do as a practice for myself. Besides that I want to write about the challenges the project provided. On the respective project page you can also find playable builds of the game and the complete source code.
I try to do them in a rather short period of time so there might be bugs and rough edges. Please also notice that the source code is not perfect and I usually make some compromises in favor of a faster development time.

About and brief history

I guess I don’t have to say alot about the mechanics of snake. You control a snake within a fixed area and try to collect food. With every food “eaten” the snake grows. If you collide with the level boundaries or the snake itself you lose.

Snake originates from the game Blockade which was developed and published by Gremlin in 1976. It then was cloned and realeased by multiple companies. The first PC version, titled Worm, was programmed in 1978 by Perter Trefonas. (Source: wikipedia)

Creating the initial playable prototype took me about an hour or so. In total I spend something like two to three hours. The game looks pretty ugly I guess (programmer art)…



Snake is a pretty simple game of course but there are still some things to consider.

So the first “problem” was the movement of the snake. How do we make sure that each part of the snake gets the correct position in each frame? My solution was to iterate over each part but backwards. So starting with the last part of the snake, I simply assign the position of it’s predecessor. I iterate over all parts and do exactly the same – always assign the position of the part with index = index – 1. For the head of course there is no predecessor. So the head just get’s moved one unit depending on the user input.

for (int i = parts.Count - 1; i > 0; i--)
GameObject prev = parts[i - 1];
parts[i].transform.position = prev.transform.position;
parts[0].transform.position += dir;

The second thing I had to think about was increasing the size of the snake whenever the player collects food. What position do I assign to the new part? This can easily be achieved by calculating the position of last part – the position of the second last and then adding this to the position of the last part.

Vector3 newPos;
Vector3 diff = lastPart.transform.position - lastPartMinusOne.transform.position;
newPos = lastPart.transform.position + diff;


The project page contains everything related to this game. It includes a playable WebGL version as well as a downloadable version for windows. The source code is also provided and can be downloaded.

That’s it for this quickie. Stay tuned for the next one!

Task List in Visual Studio

In this quicktip I want to show you the Visual Studio task list.

Many of us use keywords like ‘TODO’ or ‘HACK’ in their comments. But this only makes sense if you either got very few source files or a way to see all those comments in a central place. Luckily Visual Studio provides a view for that.

To open it just go to View -> TaskList. A new window will open. In the dropdown that says “User Tasks” simply select “Comments”. Now you see all of those “TODO”s and “HACK”s.

Open the Task List
Open the Task List
Show comments
Show comments

You can even modify the default keywords (actually they are called tokens). To do so go to Tools -> Options and select “Task List”. You can set the priority for each token and also add new ones. Adding is a bit counterintuitive. You have to enter the name for your new token in the name Textbox. After that the add button will be enabled.

Custom tokens
Custom tokens

That’s it for now. See you next time.