Creating projectiles
Now we'll create the projectile
class. It will have a sprite that's pulled from the spritesheet, and it will move from left to right at a fixed velocity.
Creating the class
To start, make a new class in the source directory named Projectile
. Here it is for reference:
package; class TestSprite2 extends FlxSprite { public function new() { super(); } }
Adding imports
Next, add the imports:
import flixel.util.loaders.TexturePackerData; import flixel.FlxSprite;
Creating variables
Now add the variables we'll be using:
private var texturePackerData:TexturePackerData; private var speed:Float = 2000;
The speed
value will be used to determine the velocity of the projectile.
Displaying the sprite and setting the velocity
After the super call in the constructor, add these lines:
texturePackerData = new TexturePackerData(AssetPaths.ingameSprites__json, AssetPaths.ingameSprites__png); loadGraphicFromTexture(texturePackerData, false, "projectile.png"); this.velocity.x = speed;
Setting...