Okay, thanks. I’m trying it with firebase by using this example: https://rexrainbow.github.io/phaser3-rex-notes/docs/site/firebase-leaderboard/
So i adjust my index.html like this:
<head>
<meta charset="UTF-8" />
<meta name=viewport content="width=device-width, initial-scale=1">
<title>infoteam-Universe</title>
<script src="lib/phaser.js"></script>
<script src="main.js"></script>
<style>
body {
background: black;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="game-container">
</div>
<script src="https://www.gstatic.com/firebasejs/7.15.0/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.15.0/firebase-analytics.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/7.15.0/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: ,
authDomain: ,
databaseURL: ,
projectId: ,
storageBucket: ,
messagingSenderId:,
appId: ,
measurementId:
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
</body>
</html>
And my Highscore.js like this:
let element;
let pointer;
var name;
class Highscore extends Phaser.Scene {
constructor() {
super("Highscore");
}
init(data){
//get score from Level.js
this.score = data.score;
this.time = data.time;
this.player = "";
}
preload() {
this.load.plugin('rexfirebaseplugin',
'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexfirebaseplugin.min.js', true);
}
create() {
this.scene.bringToTop("Sound");
//add background
let bg = this.add.image(0,0,"highscore", "background_scenes").setOrigin(0,0).setScale(1.05);
//let duration = Phaser.Math.RoundTo(this.time/60000, -1);
//add texts
this.add.text(200, 150, "RANG PUNKTE NAME",
{fontSize: "32px", fontFamily: "Consolas", fill: "#ffffff", align: "center"});
let replay = this.add.text(100, 400, "Drücke die Leertaste um nocheinmal zu spielen!",
{fontSize: "24px", fontFamily: "Consolas", fill: "#ffffff", align: "center"});
pointer = this.input.activePointer;
this.player = this.add.text(200, 200, "");
element = this.add.dom(400, 225).createFromCache("nameform");
element.visible = true;
element.addListener('click');
this.enterName();
var userID = 1;
var userName = this.player;
var leaderBoard = this.plugins.get('rexfirebaseplugin').add.leaderBoard({root: "infoteam-universe"});
leaderBoard.setUser(userID, userName);
leaderBoard.post(this.score);
leaderBoard.loadFirstPage()
.then(function(scores) { })
.catch(function(error) {
return;
});
}
update(){
/*//restart at Scene ChooseChar.js if SPACE is pressed
this.input.keyboard.once("keydown-" + "SPACE", () => {
score = 0;
this.scene.start("ChooseChar");
});
if(pointer.isDown){
score = 0;
this.scene.start("ChooseChar");
}*/
}
enterName(){
element.on('click', (event) => {
if (event.target.name === 'playButton')
{
var name = element.getChildByName('nameField');
// Have they entered anything?
if (name.value !== '')
{
element.removeListener('click');
element.setVisible(false);
this.player = name.value;
}
}
});
}
}
I created an account at firebase.google.com and added a project with a webapp.
But now my console Shows this error:
[2020-06-06T20:28:25.619Z] @firebase/firestore: Firestore (7.15.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=failed-precondition]: The Cloud Firestore API is not available for Datastore Mode projects.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
But my device has a Internet connection…what could be the issue?