Question

I have a game in which a flight will shoot bullets and when the bullet hits an enemy ship a blast effect comes and another frame loads. Now the problem i'm facing with is the blast effect and the next frame are loading at a time. So, I've added this script:

if (this.hitTest(_root["enemy1"])) {
    this.removeMovieClip();
    _root.enemy1._x=2000;
    _root.option1._x=2000;
    addExplosion(800, 200, explosionParticleAmount, explosionDistance, explosionSize, explosionAlpha);
    this._x=-900000;
    var sound:Sound = new Sound(this);
    sound.attachSound("explode");
    sound.start();
    flag = true;
    wait();
    checkAnswer(_root.option1.text);
}

function wait() {
  stop();
  var myInterval = setInterval(function () {
      play();
      clearInterval(myInterval);
  }, 5*1000); // stop for 5 seconds
}

function checkAnswer(answer){
  if(questions[level][1] == answer){  
     status_flag=true;
     score=score+10;
     bullet_fire=false;
     gotoAndStop(3);
  }else{
      bullet_fire=false;
     gotoAndStop("Scene 2",1);
  }
}

But still the result is same. I also tried increasing the time, but i am still unable to stop that another frame from pausing. Please help me out. Thank you

Was it helpful?

Solution

I think the following should work for you, though a more robust method would be to pause until you receive an event to signal that your explosion animation has completed. The problem with the current method is that if you change the length of your explosion sequence, you need to remember to update the length of your pause also.

if (this.hitTest(_root["enemy1"])) {
    this.removeMovieClip();
    _root.enemy1._x=2000;
    _root.option1._x=2000;
    addExplosion(800, 200, explosionParticleAmount, explosionDistance, explosionSize, explosionAlpha);
    this._x=-900000;
    var sound:Sound = new Sound(this);
    sound.attachSound("explode");
    sound.start();
    flag = true;
    wait();
}

function wait() {
  stop();
  var myInterval = setInterval(function () {
      //play();
      checkAnswer(_root.option1.text); // check answer after explosion has finished
      clearInterval(myInterval);
  }, 5*1000); // stop for 5 seconds
}

function checkAnswer(answer){
  if(questions[level][1] == answer){  
     status_flag=true;
     score=score+10;
     bullet_fire=false;
     gotoAndStop(3);
  }else{
      bullet_fire=false;
     gotoAndStop("Scene 2",1);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top