开发者

as3 tracking number value of variables

I have a bunch an as3 game going. In my game when newCrag hits egg_mc the score gets added.

// Add the score
var newScore:score_mc;
newScore = new score_mc();
addChild(newScore);
newScore.x = 20;
newScore.y = 20;
newScore.score_txt.text='0/15';
var score:Number=0;

function getEggs(event:Event):void {

    if(event.target.hitTestObject(MovieClip(root).newCrag) && event.target is egg_mc) {

        sndEgg.play();

        if(event.target.stage) {
            event.target.parent.removeChild(event.target);
        } 

        // Increase score
        score++;
        newScore.sc开发者_JAVA技巧ore_txt.text = "" + score + '/15';

    }

}

I am trying to refer to the number value of the score using if statements. I need to change the speed variables based off the number that is inside the score box.

var speed:Number

if(score > 10 || score == 10) {
    speed=20;
    trace("speed3");
} else if(score > 5 || score == 5 && score < 10) {
    speed=18;
    trace("speed2");
} else {
    speed=14;
    trace("speed1");
}

However, this part of the code is not working. Any help would be much appreciated.

Thanks,

Wade


Try this:

 var speed:Number; //you missed a semicolon here
 if (score>=10) {
  speed=20;
  trace("speed3");
 } else if (score>=5) {//no need to test twice for <10
  speed=18;
  trace("speed2");
 } else {
  speed=14;
  trace("speed1");
 }

Or (for interest only), all on one line:

speed = (score>=10)?20:((score>=5)?18:14);// no points for readability!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜