Josh
Josh

Reputation: 1

Score not displaying in AS3

I've got this code that mostly works. I know the ammo is being tracked correctly because I have it to be game over when the ammo runs out. My problem is that neither the score nor the remaining ammo are displaying. I'm not sure what I'm missing. Here's the code that I have relating to the issue.

package {
    import flash.display.*;
    import flash.events.*;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.media.Sound;
    import flash.media.SoundChannel;

    public class AirRaid extends MovieClip {
        private var aagun:AAGun;
        private var airplanes:Array;
        private var bullets:Array;
        public var leftArrow, rightArrow:Boolean;
        private var nextPlane:Timer;
        private var shotsLeft:int;
        private var shotsHit:int;       

        public function startAirRaid () {
            // init score
            shotsLeft = 20;
            shotsHit = 0;
            showGameScore();
        }

        public function checkForHits (event:Event) {
            for(var bulletNum:int = bullets.length - 1; bulletNum >= 0; bulletNum--) { 
                for (var airplaneNum:int = airplanes.length - 1; airplaneNum >= 0; airplaneNum-- ) {
                    if ( bullets[bulletNum].hitTestObject(airplanes[airplaneNum])) {
                        airplanes[airplaneNum].planeHit();
                        bullets[bulletNum].deleteBullet();
                        shotsHit++;
                        showGameScore();
                        break;
                    }
                }

                if ((shotsLeft == 0) && (bullets.length == 0)) {
                    endGame();
                }

            }

        }

        public function fireBullet() {
            if (shotsLeft <= 0) return;
            var b:Bullet = new Bullet(aagun.x, aagun.y, -300);
            addChild(b);
            bullets.push(b);
            shotsLeft--;
            showGameScore();
        }

        public function showGameScore() {
            showScore.text = String("Score: " + shotsHit);
            showShots.text = String("Shots Left: " + shotsLeft);
        }

    }

}

Upvotes: 0

Views: 50

Answers (1)

Vesper
Vesper

Reputation: 18747

Please check if Font Embedding property on both showScore and showShots text fields are true (checked) in GUI editor in your project. If either text field is not added in GUI, use the approach in this question AS3 - TextField: Embedded font to start embedding fonts, or set a proper defaultTextFormat to either text field somewhere at initialization.

Upvotes: 1

Related Questions