1
votes

i'm making a flash/actionscript shooter game, and this is a class i created for the bullets.

class Class.Bullet {
  public static var self:MovieClip;
  private static var interval;

  public function Bullet(X, Y) {
    self = _root.createEmptyMovieClip('self', _root.getNextHighestDepth());
    self._x = X;
    self._y = Y;
    self.beginFill(0xFFFFFF);
    self.moveTo(-2, 0);
    self.lineTo(2, 0);
    self.lineTo(2, 10);
    self.lineTo(-2, 10);
    self.lineTo(-2, 0);
    self.endFill();

    interval = setInterval(move, 1);
  }

  private function move() {
    self._x++;
  }
}

it works okay, except for some reason, beyond my understanding, each time a new bullet is created "setInterval" gets passed onto the next bullet in addition to the new setInterval.

in other words, when i shoot a second bullet, the first bullet stops moving, and the second bullet moves at twice the speed.

cheers!!

P.S: i'm using as2

1

1 Answers

0
votes

When you use createEmptyMovieClip you need to make sure each new clip is given a unique name. It's a while since I used ActionScript 2.0, but I think a common pattern was to append the depth to the name, like this:

 var depth = _root.getNextHighestDepth();
 self = _root.createEmptyMovieClip('self_' + depth, depth);