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

Adding movement patterns to enemies

Now that we've loaded in our pattern data and have a pool for enemies to be spawned from, let's update our Enemy class to work with movement patterns and allow them to be recycled when they move offscreen or get shot.

Adding imports

To start, open the Enemy class and add this import:

import flixel.util.FlxPoint;

The FlxPoint object is an object that contains the x and y values. We'll be using this class to define each point that the enemy will move to.

Adding variables

Next, let's add the new variables we'll need.

private var movementSpeed:Float;
private var movementPattern:Dynamic;
private var movementPoints:Array<FlxPoint>;

Here's the explanation of the code:

  • The movementSpeed variable will store the speed value of ...

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