高分变量不适用于游戏

时间:2016-05-03 19:14:05

标签: javascript html phaser-framework

我目前正在使用Phaser开发游戏,并尝试实施一个系统来保存当前得分的高分。由于某种原因它不起作用,我不知道为什么,它似乎不会根据当前分数改变高分变量。 我把这个简单的游戏放在Jsfiddle上,代码在这里:https://jsfiddle.net/zpy8wLqf/ 这就是我为高分变量所尝试的。

highscore=0;
var currentscore;
if(this.currentscore>highscore){
    highscore =this.currentscore;
}

纹理不存在,但这应该不是问题。

1 个答案:

答案 0 :(得分:3)

那是因为你的支票只在状态开始时运行,试着把支票放在重置

reset: function() {
    if(this.currentscore>highscore){
    highscore =this.currentscore;
    }
    // Start the 'main' state, which restarts the game
    begin.state.start('adventure');
}