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

Updating enemies

We're going to add some new art and functionality to our enemies. We'll add a two-frame looping animation that will make the enemies seem livelier.

The enemies will be made to spawn offscreen on the right and at a random y coordinate. They will fly across to the left side of the screen. After flying to the left side of the screen they will respawn on the right side of the screen at a new y coordinate and begin again.

They will also have a function that can be called when they are destroyed by the player. This will fade them out and then make them respawn.

To start, open Enemy.hx so we can make the changes we need.

Adding imports

To start, let's add the new imports we'll need:

import flixel.FlxG; import flixel.tweens.FlxTween; import ...

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