我正在制作一款游戏,用户将在游戏结束时查看他/她的高分和得分。这是玩家看到结果页面时的代码:
function showresults():void
{
var so:SharedObject = SharedObject.getLocal("alltimeHighScore");
if (so.data.score == undefined || score > so.data.score)
{
endscreen_mc.scoreR_txt.text = String(score);
endscreen_mc.highscore_txt.text = String(score);
}
if (score < so.data.score)
{
endscreen_mc.scoreR_txt.text = String(score);
endscreen_mc.highscore_txt.text = String(so.data.score);
}
so.data.score = score;
so.flush();
}
它有时会填充,有时则不会填充。我的另一个级别也有类似的代码:
function showresultsA():void
{
var so:SharedObject = SharedObject.getLocal("alltimeHighScore");
if (so.data.scoreA == undefined || scoreA > so.data.scoreA)
{
endscreenA_mc.Ascore_txt.text = String(scoreA);
endscreenA_mc.highscoreA_txt.text = String(scoreA);
}
if (scoreA < so.data.scoreA)
{
endscreenA_mc.Ascore_txt.text = String(scoreA);
endscreenA_mc.highscoreA_txt.text = String(so.data.scoreA);
}
so.data.scoreA = scoreA;
so.flush();
}
答案 0 :(得分:0)
我注意到的一件事是,当so.data.score等于得分时,它们不是条件声明。
if(so.data.score==score){
}
如果代码运行时这是真的那么显然文本不会更新。除此之外,由于您的代码示例很短,我无法提供其有时无法显示的其他原因。
答案 1 :(得分:0)
所以,请尝试更改你的函数showresults(),如下所示:
function showresults():void
{
// display current score
endscreen_mc.scoreR_txt.text = String(score);
// calculate, display and save (if necessary) a new highscore
var so:SharedObject = SharedObject.getLocal("alltimeHighScore");
if (!so.data.score || score > so.data.score)
{
endscreen_mc.highscore_txt.text = String(score);
so.data.score = score;
so.flush();
}
else
{
endscreen_mc.highscore_txt.text = String(so.data.score);
}
}