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 the pattern. ThemovementPattern
variable will store the pattern data specific to this enemy.The
movementPoints
array will store an array ofFlxPoint
objects, and we'll convert the array ofpoints
from theJSON
data to theFlxPoint
objects. This...