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 ...

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.