2016年10月1日 星期六

LibGDX Localization in Asian Languages

About this topic, this is mainly for non-alphabetical written languages such as Chinese, Japanese, Korean and various others.  For those non-Latin languages if you have trouble displaying some alphabets, I think this may be useful too.

LibGDX uses .properties files to handle localization.  If you do not know the basic of localization in LigGDX, you should look at Internationalization and Localization at LibGDX wiki first.

In Android Studio at your assets directory:
  1. right click --> New --> Resources Bundle
  2. In "Resource bundle base name, type "MyBundle_zh.properties", zh can be change to the language you want to use.
  3. Click "OK"
In the properties file, you can just type all the phrases in the languages, like in the LibGDX page:

game=我的超級酷遊戲
newMission={0}, 你有一個任務,到達第{1}關
coveredPath=你已包含 {0,number}% 的路
highScoreTime=最高分數在{0,date} 時間 {0,time} 達到
 Ok, so now to display, let's say the "game", you use:


String text = bundle.get("game");
Whatever methods you use for displaying, and it wouldn't work, you need to do a few thing before they can displayed.

First you need to create the .fnt files for your language in Hiero.  The way I open Hiero is to download here and open it.

Then choose your language font, in sample text just paste all the characters in it like below:



and then File --> Save Bitmap Font files to your assets directory.  It will save a .fnt file and .png file.

Next thing you need to set the encoding in your I18Bundle.  For Traditional Chinese the encoding is "big5" like this:

public void setLanguage() {
	Locale locale = Locale.getDefault(); //This will get default language of the device
	String encoding = "utf-8"
	if (locale.getLanguage().equals("zh")) {
	    encoding = "big5";
	    Texture texture = new Texture(Gdx.files.internal("fonts/chinese.png"));
            texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            font = new BitmapFont(Gdx.files.internal("fonts/chinese.fnt"), new TextureRegion(texture), false);
	} else {
	    Texture texture = new Texture(Gdx.files.internal("fonts/english.png"));
            texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            font = new BitmapFont(Gdx.files.internal("fonts/english.fnt"), new TextureRegion(texture), false);
	}
	bundle = I18NBundle.createBundle(Gdx.files.internal("i18n/MyBundle"), locale, encoding);
}
Now everything should work properly.

One more thing your computer language setting should also be the same language you are editing MyBundle file and running Hiero otherwise they are in different encoding and will not show properly.  So let's say I want to also include Simplified Chinese.  I need to set my computer in Simplified Chinese and reboot to do it.

This is simple if you don't have many words.  If you make like a Chinese word games I can see it will be a pain to edit in Hiero.


2016年9月30日 星期五

How Did I Start Game Development

This is my new blog.  I would want to share some of the experiences I encountered which other blogs have not covered.

I first began learning android development on Udacity, which covered Android, Java, and also libGDX.  I first take the Android Development for Beginners.  Then I found that I need to under Java programming (the beginner course said you don't need programming experience, but without them it's hard to understand why certain codes were there), so I take the Intro to Java Programming.  Then I tried the Developing Android Apps which is the intermediate Android course.  I stopped halfway through as some contents are going too fast and I need to find courses to help with the stuffs I need to know, such as udemy.com, youtube, etc.

After that I need to find a game engine.  Since libGDX requires programming in Java while others such as Unity requires other programming languages, I choose libGDX to begin with.  There are two libGDX courses in Udacity which I found through Google search.  The link is here:

2D Game Development with libGDX

How to Make a Platformer Using libGDX

That's it for now.  And I hope I can write something interesting to those who wants to learn some basic.