Running Flash 8, Actionscript 2.0
Basically, i'm writing a script for a Space Invaders-like game (nothing too fancy) with all the MovieClips created dynamically and animated dynamically. The issue i'm getting is that when i try to
make the enemy invaders move, the one on the very far left, starts to very very slowly become out of sync with the rest of the line (position wise) it moves a little bit more to the left everytime the line of invaders reverses direction. I feel i should also note that Flash doesn't seem to find an error either XD
Below is my code for creating and moving the invaders.
//---------------------------------------
//create the enemies using a "for" loop
//--------------------------------------
for(var e:Number = 0; e <= 7; e++){
var enemyHandler = this.attachMovie("mcMob2","enemyB"+e,_level0.getNextHighestDepth());
enemyHandler._x = 5 + nEnemySpacing + enemyHandler._width;
enemyHandler._y = 125 + nEnemyLineGap;
nEnemySpacing += (25 + enemyHandler._width);
aEnemyArray.push(enemyHandler);
if (e==3){
nEnemyLineGap += (enemyHandler._height+(enemyHandler._height/2));
nEnemySpacing = nEnemyOriginalSpacing;
}
}
//---------------------------------------
//move All the enemies using a function with a for loop
//---------------------------------------
function moveEnemies(){
for (var m:Number = 0; m < aEnemyArray.length; m++){
aEnemyArray[m]._x += nEnemySpeed;
if((aEnemyArray[m]._x >= (580 - aEnemyArray[m]._width)) || (aEnemyArray[m]._x <= 20)){
nEnemySpeed = -nEnemySpeed;
}
}
}
//Run all functions every frame. (24 times a second)
this.onEnterFrame = function() {
fireBullet();
killShot();
moveEnemies();
}
And here are the declared variables
//Enemy Variables
var nEnemySpeed:Number = 3;
var nEnemyDrop:Number = 15;
var aEnemyArray:Array = new Array();
var nEnemySpacing:Number = 25;
var nEnemyLineGap:Number = 0;
var nEnemyOriginalSpacing:Number = 25;
I cant for the life of me find the error, so im wondering if any of you guys & gals out there with the know-how have any ideas XD
Thanks in advance to anyone who replies!
Basically, i'm writing a script for a Space Invaders-like game (nothing too fancy) with all the MovieClips created dynamically and animated dynamically. The issue i'm getting is that when i try to
make the enemy invaders move, the one on the very far left, starts to very very slowly become out of sync with the rest of the line (position wise) it moves a little bit more to the left everytime the line of invaders reverses direction. I feel i should also note that Flash doesn't seem to find an error either XD
Below is my code for creating and moving the invaders.
//---------------------------------------
//create the enemies using a "for" loop
//--------------------------------------
for(var e:Number = 0; e <= 7; e++){
var enemyHandler = this.attachMovie("mcMob2","enemyB"+e,_level0.getNextHighestDepth());
enemyHandler._x = 5 + nEnemySpacing + enemyHandler._width;
enemyHandler._y = 125 + nEnemyLineGap;
nEnemySpacing += (25 + enemyHandler._width);
aEnemyArray.push(enemyHandler);
if (e==3){
nEnemyLineGap += (enemyHandler._height+(enemyHandler._height/2));
nEnemySpacing = nEnemyOriginalSpacing;
}
}
//---------------------------------------
//move All the enemies using a function with a for loop
//---------------------------------------
function moveEnemies(){
for (var m:Number = 0; m < aEnemyArray.length; m++){
aEnemyArray[m]._x += nEnemySpeed;
if((aEnemyArray[m]._x >= (580 - aEnemyArray[m]._width)) || (aEnemyArray[m]._x <= 20)){
nEnemySpeed = -nEnemySpeed;
}
}
}
//Run all functions every frame. (24 times a second)
this.onEnterFrame = function() {
fireBullet();
killShot();
moveEnemies();
}
And here are the declared variables
//Enemy Variables
var nEnemySpeed:Number = 3;
var nEnemyDrop:Number = 15;
var aEnemyArray:Array = new Array();
var nEnemySpacing:Number = 25;
var nEnemyLineGap:Number = 0;
var nEnemyOriginalSpacing:Number = 25;
I cant for the life of me find the error, so im wondering if any of you guys & gals out there with the know-how have any ideas XD
Thanks in advance to anyone who replies!
