Move Enemy

Create the MoveEnemy Function

Let's get the moveEnemy function started. It doesn't really matter where you put it, as long as it exists as it's own discrete function. We'll talk about schemes for organizing our code later:

Our enemy will to the left across the screen. Let's reference a variable called enemySpeed:

Of course, we'll need to declare the enemySpeed variable. We'll group that up at the start of our code:

Finally, we need to call the moveEnemy function if we ever want those actions to run. Since we want our enemy to continually move, moveEnemy should be part of the onEnterFrame function:

In the example below I added a "PLAY" button just so you can see what your project should look like when you test it. You do NOT need to add the "PLAY" button. The enemy should move horizontally across the screen and disappear into oblivion:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player