• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

removin bullets from stage after game over

Community Beginner ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

in my game enemy Planes shoot at my plane and everything is working fine

enemy bullets are inside an array

the problem is when my plane gets destroyed by enemy Planes ,the last bullets shot by the enemyPlanes still shows on the screen

eventhough i called a removelistener function and added a game over screen

enemy planes use timer which i have a listener for it

how can i remove the last bullets that still shows on the screen?

TOPICS
ActionScript

Views

878

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 07, 2012 Apr 07, 2012

yep, and clear the array

Votes

Translate

Translate
LEGEND ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

If the bullets are stored in an array, then use removeChild to remove them and set any references to them as null.  Empty the array when you are done.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

// responsible for making an enemy plane shoot when the timer start

public function e1ShootBullet(event:TimerEvent):void

        {

            //Create a bullet and add it to the stage

            enemyBullet1 = new Bullets(getAngle2(enemyPlane1));

            stage.addChild(enemyBullet1);

            //Set the bullet's starting position

            var radius:int = 30;

            var angle:Number = enemyPlane1.rotation * Math.PI / 180;

            enemyBullet1.x = enemyPlane1.x + radius * Math.cos(angle);

            enemyBullet1.y = enemyPlane1.y + radius * Math.sin(angle);

            //Set the bullet's velocity based

            //on the angle

            enemyBullet1.vx = Math.cos(angle) * 5;

            enemyBullet1.vy = Math.sin(angle) * 5;

            //Push the bullet into the _bullets array

            _eBullet.push(enemyBullet1);

            //Find a random start time for the next bullet

            var randomFireTime:Number = Math.round(Math.random() * 1000) + 200;

            //_timer1.delay = randomFireTime;

        }

// responsible for moving the enemy Planes bullets called from an enter frame function

private function moveEnemyBullet( enemyPlane :MovieClip)

        {

            if (enemyPlane == enemyPlane1)

            {

                for (var i:int = 0; i < _eBullet.length; i++)

                {

                    enemyBullet1 = _eBullet;

                    enemyBullet1.x +=  enemyBullet1.vx;

                    enemyBullet1.y +=  enemyBullet1.vy;

                    if (enemyBullet1.y < 0 || enemyBullet1.x < 0 || enemyBullet1.x > stage.stageWidth || enemyBullet1.y > 609)

                    {

                        //Remove the bullet from the stage

                        stage.removeChild(enemyBullet1);

                        bullethit.play();

                        //Remove the bullet from the _bullets;

                        //array

                        _eBullet.splice(i,1);

                        enemyBullet1 = null;

                        //Reduce the loop counter

                        //by one to compensate

                        //for the removed bullet

                    }

}

}

// end Game function

private function endGame( endMessage:String):void

        {

            endScreen = new winLoose();

            endScreen.end_txt.text = endMessage;

            //endScreen.score_txt.text = String(_PlaneScoreDisplay);

            addChild(endScreen);

            endScreen.x = 0;

            endScreen.y = 0;

            _timer1.removeEventListener(TimerEvent.TIMER, e1ShootBullet);

            _timer2.removeEventListener(TimerEvent.TIMER, e2ShootBullet);

            _timer1.stop();

            _timer2.stop();

           

            _PlaneScoreDisplay.text = "";

            bombsLeftDisplay.text = "";

            endScreen.playAgain_btn.addEventListener(MouseEvent.CLICK, startGame);

        }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

I am not sure why you are showing the code without any explanation, but I do not see where you are removing any of the bullets in your endGame function, which is where you say you wanted them to go away... you only do it in your moveEnemyBullet function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

damn i missed that  ^^ damn i just get lost in my own code

i should do the same

stage.removeChild(enemyBullet1);

          enemyBullet1 = null;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2012 Apr 07, 2012

Copy link to clipboard

Copied

LATEST

yep, and clear the array

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines