如何绘制一系列分数?

时间:2017-02-23 20:42:13

标签: actionscript-3

我正在尝试制作得分图。我有七场比赛的得分。我可以使用graphics.lineTo功能,但需要很长时间 有一个简单的方法吗?

示例图。

enter image description here

这是我到目前为止所尝试的内容。我制作了20-40-60-80行movieclip并复制并更改了每个级别的名称。

                if(score1 == 40 && score2 == 20  && makeline == true){
        line20.x = 184;
        line20.y = 411;
        yirmiasah2 = true;//yirmi asa
    }
                    if(score1 == 40 && score2 == 40  && makeline == true){
        line40.x = 184;
        line40.y = 411;
    }
                        if(score1 == 40 && score2 == 60  && makeline == true){
        line60.x = 183;
        line60.y = 366;
    }
                                if(score1 == 40 && score2 == 80  && makeline == true){
        line80.x = 172;
        line80.y = 384;
    }

1 个答案:

答案 0 :(得分:2)

问题不明确但你可以尝试这样的事情。

在你的代码的某个地方,你无疑拥有一个保持当前游戏得分的变量。你没有证明这一点,所以我会在currentScore类型的最后一场游戏int中调用当前得分。首先,此变量在任何函数之外声明。

var currentScore:int;

然后,在玩游戏时,只要玩家获得积分,该值就会上升。在我的例子中,当Sprite A接触Sprite B时,他得到一个点

if (spriteA.hitTestObject(spriteB)){
    newScore++; // adds one to the newScore variable
}

制作一个数组来保存你的分数。把它放在任何函数之外。将它放在currentScore变量的同一位置是有道理的。

var scoreArray:Array = new Array();

由于每个分数都是最终的(在游戏结束时),请将该分数添加到数组中:

if (gameOver == true){
    // make a new variable to add to the array and give it the same value as the score of the last game
    var newScore:int = currentScore;

    // add the new variable to the array
    scoreArray.push(newScore);
    // this adds the newScore variable to the array.
    // after 7 games, you'll have 7 values in the array. 
}

然后绘制图表:

var scoreGraph:Sprite = new Sprite();
addChild(scoreGraph);
scoreGraph.graphics.moveTo(0,100);
scoreGraph.graphics.lineStyle(1);
for (var i:int = 0; i < scoreArray.length; i++){
    scoreGraph.graphics.lineTo(i*10,100-scoreArray[i]);
    // this will space out along the x axis by 10 pixels and put the x axis at 100 pixels down.
}