Basically what I’m trying to do is make a very simple vertical bullet projectile system (bullets move at a consistant pace, bullets can have a hitTestObject applied, etc), but I’m having difficulties putting something together.
At-the-moment my code is:
// define timer
var myTimer:Timer = new Timer(15);
// define array [list]
var list:Array = new Array();
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
function timerListener(e:TimerEvent):void
{
var Create:Bullet = new Bullet();
addChild(Create);
// Starting position
Create.x = 150;
Create.y = 150;
// Push into list
list.push(Create);
}
for (var i:int; i <= 10; i++){
list[i].x + 10;
i++;
if (i > 10){
i = 0;
}
}
The problem is I’ve been having all kinds of issues using for/while/etc when it comes to trying to reference list[i].x and having all the objects move at a consistant pace, including #1010 errors.
If anyone knows a better way to do what I’m looking for, or the fix to my current code, it would be much appreciated. 🙂
When you are moving your list of bullets, you need to properly index the list. The reason you are getting #1010 ‘undefined’ errors is because list[i] is not always defined. You should also remove any bullets that have moved off the screen. I used 300 pixels as an arbitrary cut-off point. you should call moveBullets() on a timer, possible on your 15ms timer above.
try this: