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
.
Updating GameHUD
Open GameHUD
and add the imports we need:
import ui.Strings; import ui.StringIDs;
After this, go into the constructor and replace the line that mentions the text
property on txtHealthHeader
with this:
txtHealthHeader.text = Strings.instance...