Adding a background and basic UI

We're going to start by adding a background, and two text fields to display the score and game time to the player. Open up PlayState.hx, and we'll add some variables.

Inside the class, add the following variables:

private var background:FlxSprite;
private var txtScore:FlxText;
private var txtTime:FlxText;

The background is a FlxSprite object. It is used when you want to display an art asset or a shape drawn by HaxeFlixel. The txtScore and txtTime variables are FlxText objects, and as the name implies, they're used to display text.

After this, go inside the create function and add the following underneath super.create():

background = new FlxSprite(); background.loadGraphic(AssetPaths.gameBackground__png); add(background); ...

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.