Recent Blogposts | Page 11

Java String Split Gotcha

Oct. 6, 2015, 2:12 p.m. Programming

I was fixing a networking-related bug in Koloniigo. I did something like this:

String[] fields = data.split(";"); //data contains something like "a;b;;"
foo(fields[3]);

Then the program gave IndexOutOfBoundsException

I wonder what's wrong. After a few hours of debugging, I found this thingie in the documentation of split()

Trailing empty strings are therefore not included in the resulting array.

Oh well, wtf? A few hours wasted.

You may think that I'm an idiot that I didn't notice such an obvious mistake. Actually, the real code is way more complicated and there was very many possible causes of the issue. That's why it took me so long to figure out that it's the issue of the split(). :(


[WIP]Koloniigo - Networked Game Progress

Sept. 30, 2015, 4:28 p.m. Gamedev Koloniigo WIP

Hi. I haven't updated the development progress for a while because I have been busy working on the game. :3

As you might have know, networking is tough. Anyway, I'm getting good progress on it. And I managed to get cross-platform websocket networking working. :D

Here's what networking function currently implemented:

  • Automatically register players(for future use. Mainly for storing player experience)
  • Minimal lobby server. It waits for two players joining a networked game, then redirect the two players to enter a game room.

Here's what still left to be implemented:

  • Actual networked game. (The networking stuffs after the two players entering the game room)

It's midnight here. I'm exhausted. Time to sleep. I'll continue work on this game tomorrow. Good night guys! <3


[WIP]Koloniigo - Tutorial

Sept. 19, 2015, 8:30 a.m. Gamedev Koloniigo WIP

I've just implemented 3 tutorial levels in Koloniigo. It's used to briefly introduce the game mechanism.

Before completing the tutorial, Random Map mode and Network Mode(unimplemented) are locked. They're unlocked once you finish it.

So what's left are:

  • Networked Game
  • Achievements
  • maybe more later :P

I'm current doing research on making networked game work. I'm planing to write a wrapper library to make a unified interface for accessing Java-WebSocket(for android build) and gwt-websockets(for html5 build).

After the research, I will take a break in this project for updating my website(well, the home page is severely outdated). I'll probably merge this blog with the homepage. The project will continue after the completion of website update.

Let's see how will it turned out. I'll post any future update here! :)


[WIP]Koloniigo - Viewing Building Feature

Sept. 17, 2015, 2:53 a.m. Gamedev Koloniigo WIP

As you might have know, each building in Koloniigo has a special feature. For example, hospital has 2x population generation among other buildings.

Now I've implemented a speech bubble that shows the feature of the building:

Not counting networked game, this game is almost finished. I will report future updates on development in this blog. :)


Gotcha of Rendering libgdx NinePatch

Sept. 15, 2015, 1:22 p.m. Gamedev Programming libgdx

Today I ran into a gotcha of libgdx. I was trying to render a NinePatch packed with texture packer by constructing a NinePatch using this:

new NinePatch(assetManaget.get("pack.atlas", TextureAtlas.class).findRegion("path/to/ninepatch"));

Then I tried to render the object using its draw() method. Didn't work. Instead, the NinePatch image was just stretched.

Then I read the documentation about the constructor of new NinePatch(TextureRegion)

Construct a degenerate "nine" patch with only a center component.

What? This is obviously not what I was expecting.

Turned out that the proper way to do this is:

assetManaget.get("pack.atlas", TextureAtlas.class).createPatch("path/to/ninepatch");

See also: TextureAtlas.createPatch(java.lang.String)