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);
In those lines, we are creating a new FlxSprite
instance in the background
variable, loading our background image using the AssetPaths
class, and then using the add
function to add the background to PlayState
. The add
function is inherited from...