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

Making the player character

Finally, we will create our player character and the namesake of our game, the Star Walrus! This walrus will also have a two-frame animation loop like the enemies.

Since this is a game that will be playable on both desktop and touch-based platforms, we'll be keeping the walrus controls nice and simple. The walrus will automatically shoot while the player moves it around the screen using the keyboard, mouse, or touch input.

Creating the class

First, let's create the class. In the source folder, make a new class named Player that extends FlxGroup:

package;

import flixel.group.FlxGroup;

class Player extends FlxGroup
{
  public function new() 
  {
    super();
  }
}

Adding imports

Next, let's add the imports:

import flixel.FlxSprite; import ...

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