Untitled
10 months ago in HAML
<html>

<head>
<script src="https://cdn.jsdelivr.net/npm/phaser-ce@2.16.1/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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52