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 ...

Get Haxe Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.