Hey, thanks for the reply.
I guess I should be more specific.
So each enemy spawns in based upon a timer. For this, I use a custom Timer that can receive parameters that are accessible when a TimerEvent is fired. I use the DataTimer class, a really handy snippet of code I found Here.
// I run this bit of code before the game loop runs.
function buildLevels ():void
// Create all enemy types here.
// new enemy( Name:String, distr:String, frequency:int, VX:int, VY:int, startX:int, startY:int,
//AX:int, AY:int, BMD:BitmapData, BAD:Boolean, pts:int ):void
en1 = new enemy( "pellet", "even", 200, -10, 0, right - 1, hero.y, 0, 0, greyParticles, true, 10 );
en2 = new enemy( "boulder", "even", 2000, -1, 1, right * Math.random(), 1, 0, 0, greyParticles, true, 30 );
// Create level object.
level1.enemies = [en1, en2];
level1.name = "level1";
levels.push ( level1 );
The real problem is in the code above, not below. Take en1, for example. I want its starty to be the hero's y position. Ideally, that would be calculated in my timerCallBack function, since the hero's y position will always be changing. But I can't think of a good way to do this
// Prepare the level based on level1 object.
var theLevel:Object = levels[ currentLevel ];
for (var i in theLevel.enemies)
var e:enemy = theLevel.enemies[i];
// the data timer class extends the timer class.
// it's basically a timer that can receive parameters on TimerEvents
var myTimer:DataTimer = new DataTimer( e.freq, 0 );
// In this instance, the TimerEvent receives an instance of each enemy object 'e'
myTimer.data.enemyData = e;
// Let's start this enemy's timer and add a listener to it.
myTimer.addEventListener (TimerEvent.TIMER, timerCallBack);
// Add the timer to an array of like-minded timers so we can manipulate them later.
enemyTimers.push ( myTimer );
function timerCallBack (event:TimerEvent):void
// An enemy timer is ready,
// Extract the data from the DataTimer
var tmr:DataTimer = event.currentTarget as DataTimer;
var e = tmr.data.enemyData;
// And transpose extracted data onto a new enemy clip.
var myEn:p = new p();
myEn.name = e.name;
// So, this is the problem,
// e.startx and e.starty were already calculated...
// in this example, en1's starty position is hero.y,
// which should change as the game loop runs.
// but here it is completely static since it's calculated
// before the game loop starts.
myEn.x = e.startx; // THIS IS WHERE THE PROBLEM IS.
myEn.y = e.starty; // THIS IS WHERE THE PROBLEM IS.
myEn.vx = e.vx;
myEn.vy = e.vy;
myEn.bad = e.bad;
myEn.bmd = e.bmd;
// Add new enemy to enemiesArray
ez.push ( myEn );
Hopefully that makes more sense now.