<html>
<head>
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/build/phaser.js"></script> </head>
<body>
<script>
var width = window.innerWidth ;
var height = window.innerHeight ;
var game = new Phaser.Game(width, height, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, render: render });
var counter = 0;
var text = 0;
var timer;
function preload() {
game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;
}
function create() {
game.stage.backgroundColor = '#6688ee';
text = game.add.text(game.world.centerX, game.world.centerY, '0', { font: "128px sans", fill: "#ffffff", align: "center" });
text.anchor.setTo(0.5, 0.5);
timer = game.time.events.loop(Phaser.Timer.SECOND, updateCounter, this);
game.input.onTap.add(onTap, this);
}
function render() {
}
function setTimer(v) {
counter = v;
text.setText(counter);
}
function updateCounter() {
setTimer(counter + 1);
}
function onTap() {
game.time.events.remove(timer);
timer = game.time.events.loop(Phaser.Timer.SECOND, updateCounter, this);
setTimer(0);
}
</script>
</body>
</html>