FlashComponents
  Flash Templates
  Flash Gallery
  Flash Slideshow
  Flash Menu
  Flash Design
  Flash Video
  FLV Player

 

 

 

 


Creating a Vertical Shooter - Page 2
       by Ernesto Quezada aka _Bruno : January 22 2006

In the previous page, I started explaining the code for getting our hero Pawel to move. We will keep making modifications to our code, but in this page, I will finish up my code explanation.

Let's go through the code you used in the previous page:


//---- variables ----
var steps:Number = 5;
var spriteX:Number = 265;
var spriteY:Number = 265;

First we declare the variables, steps are the number of pixels our hero will move, spriteX and spriteY will help us to give value to the X and Y position of our hero.


The first function checks if we are pressing the keys that are making our hero to do things:

if (Key.isDown(Key.RIGHT) && spriteX<510) {
spriteX += steps;
knight.legs.play();
}

The above code essentially says that only if we press the Right arrowKey and our hero is not outside of the stage, our hero will move to the right (remember, steps = 5 pixels) and play the legs animation.


else if (Key.isDown(Key.LEFT) && spriteX>40) {
spriteX -= steps;
knight.legs.play();
}

This code is the same as above, except I now check for the Left arrow key and ensure that our hero is not outside the left edge of our stage.
If we press the Up arrowKey on our keyboard, the animation in our arms movieclip will play.


function updatePawel() {
knight._x = spriteX;
knight._y = spriteY;
}

This function tells Flash that our hero will take the X and Y values of the variables spriteX and spriteY.


this.onEnterFrame = function() {
checkKeys();
updatePawel();
};

This onEnterFrame event checks to see if we are pressing keys on the keyboard or if our hero is moving.


Onwards to the next page!


page 2 of 4


 


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components
flash menus, buttons and components Digicrafts Components
The best flash components ever! Entheos Flash Website Templates
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
Streamsolutions Content Delivery Networks Buy and sell FLAs.
cdn
      content delivery network (cdn)
Flipping Book - page flip flash component. Learn how to advertise on kirupa.com