O'Reilly logo

Haxe Game Development Essentials by Jeremy McCurdy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Replacing strings

Now we'll go and replace the strings that we have hardcoded throughout the game. There are strings in three classes in the game: MenuState, GameHUD, and LevelEndScreen.

Updating MenuState

Open up MenuState and add the following imports:

import ui.Strings;
import ui.StringIDs;

After this, go in the create function and add this immediately after the super.create function call:

Strings.instance.init();

This will load and set up our XML data. Then, we can just get at the data whenever we need it.

Now still inside the create function, go down to the line where the text property is set on txtInstructions and replace it with this:

txtInstructions.text = Strings.instance.getValue(StringIDs.TAP_TO_START);

That's all we need to do in MenuState ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required