var Timer = Container.expand(function () { var self = Container.call(this); self.time = 0; self.updateTime = function () { self.time += 1; }; self.getTime = function () { return self.time; }; }); var Game = Container.expand(function () { var self = Container.call(this); var timer = self.addChild(new Timer()); var timerDisplay = new Text2('Timer: 0', { size: 150, fill: "#ffffff", align: 'center' }); timerDisplay.anchor.set(0.5, 0.5); timerDisplay.x = 2048 / 2; timerDisplay.y = 2732 / 2; LK.gui.addChild(timerDisplay); LK.on('tick', function () { timer.updateTime(); timerDisplay.setText('Timer: ' + timer.getTime()); }); });
===================================================================
--- original.js
+++ change.js
@@ -10,9 +10,18 @@
});
var Game = Container.expand(function () {
var self = Container.call(this);
var timer = self.addChild(new Timer());
+ var timerDisplay = new Text2('Timer: 0', {
+ size: 150,
+ fill: "#ffffff",
+ align: 'center'
+ });
+ timerDisplay.anchor.set(0.5, 0.5);
+ timerDisplay.x = 2048 / 2;
+ timerDisplay.y = 2732 / 2;
+ LK.gui.addChild(timerDisplay);
LK.on('tick', function () {
timer.updateTime();
- console.log('Time: ' + timer.getTime());
+ timerDisplay.setText('Timer: ' + timer.getTime());
});
});