Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript 3: dynamic text help: scoring for game

I am very new to action script 3, and I am trying to make a very basic game right now. However, no matter how many pages I look at I can't find a working way to get my game to keep score :/.

What I am trying to do is make it so that every 10 seconds, 10 points is added to the score (right now I have it replaces with a key, to see if I could get that to work, but it didn't). This is the code I am trying to use right now:

    var playerScore:int = 0

    stage.addEventListener(MouseEvent.CLICK,onclick);

    function updateTextFields():void{
         playerScoreText.text = ("Player Score: " + playerScore);
    }

    if(Key.isDown(Key.G)){
          playerScore++; //increase playerScore by 1
          updateTextFields();
    }

playerScoreText is the name of the dynamic text any help will be greatly appreciated :)

This code was all added in Timeline

I am thinking the problem is most likely something with the creation of the dynamic text, but I am not sure.

like image 445
jackbtroop62 Avatar asked Jan 07 '13 21:01

jackbtroop62


2 Answers

Make sure the fonts are embedded properly and that the color of the dynamic text field is not same as the background.

also instead of writing

playerScoreText.text = ("Player Score: " + playerScore);

try this

playerScoreText.text = "Player Score: " + String(playerScore);
like image 194
Joe Slater Avatar answered Nov 11 '22 05:11

Joe Slater


It sounds like you want to do something like this with the timer class. Your key code isn't written properly.

var playerScore:int = 0;
var score_timer:Timer = new Timer(10000,0);
score_timer.addEventListener(TimerEvent.TIMER,updateTextFields);
score_timer.start();
function updateTextFields(e:TimerEvent):void
{
    playerScore+=10
    playerScoreText.text = ("Player Score: " + playerScore);
}
like image 34
lostPixels Avatar answered Nov 11 '22 06:11

lostPixels