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

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

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