在Phaser中创造高分 [英] Create a High Score in Phaser

查看:92
本文介绍了在Phaser中创造高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次通过我编写的教程创建游戏,因此我是一个全新的人,但我渴望学习.

This is my first time creating a game via a tutorial which I've coded along with so I am a completely new at this but I am eager to learn.

我拥有这款游戏"Bunny Defender",并希望创建一个简单的高分",我可以使用XML将其存储在某种本地存储中,并在游戏结束时在屏幕上显示高分结果.

I've this game "Bunny Defender" and want to create a simple High Score which I can store in some kind of localstorage with XML and display the high score result out on the screen when the game is over. 

我不知道该怎么做以及从哪里开始.如果有人能指出我正确的方向以及如何管理这个方向,会非常感激吗?

I don't know how to do this and where to start. Would be very thankful if someone could point me at the right direction and how to manage this?

//github上的所有游戏文件 https://github.com/eiffelqiu/bunny-defender

// All the game files on github https://github.com/eiffelqiu/bunny-defender

推荐答案

为什么需要XML?东西作为键值对存储在localStorage内,因此在一般情况下,将其设置就足够了:

Why would you need XML? Stuff is stored inside localStorage as key-value pairs, so in the general case this would be enough to set it:

var highScore = 100; // you would've set this earlier, of course
localStorage.setItem("bunnyDefenderHighScore", highScore); // game-specific key in case you later run another game on the same domain

...以及要检索的内容:

... and this - to retrieve it:

var highScoreToDisplay = 0;
if (localStorage.getItem("bunnyDefenderHighScore") !== null) {
    highScoreToDisplay = parseInt(localStorage.getItem("bunnyDefenderHighScore"));
}

然后,只要您想显示它,就做

Then, whenever you want to display it, do

var gameOverText = this.game.add.text(100, 100, highScoreToDisplay.toString(), {font: "20pt Arial", fill: "#FFFFFF"});

这篇关于在Phaser中创造高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆