Ninjadoodle Posted September 4, 2018 Share Posted September 4, 2018 Hi panda people! Just wondering whether somebody can help me with this. I've been looking around, but can't seem to find an easy way to format my timer. Basically I would like to display seconds:milliseconds, in this format 00:00 I currently have this, and managed to pad the seconds when it goes into single digits, but I'm struggling a bit, to only display 2 digits on the milliseconds. Thanks in advance for any tips game.module( 'game.game' ) .body(function() { game.createScene('Game', { init: function() { // TIMER this.countdownTxt = new game.Text('00:00'); this.countdownTxt.anchor.set(this.countdownTxt.width / 2, 0); this.countdownTxt.addTo(this.fg); this.countdownTxt.position.set(640, -0.5*(game.system.height - 1920) + 64); this.countdownTimer = game.Timer.add(10000, function() { // DO STUFF }); }, pad: function(number, length) { var str = '' + number; while (str.length < length) { str = '0' + str; } return str; }, update: function() { // TIMER var milliseconds = parseInt((this.countdownTimer.time()%1000)); var seconds = parseInt((this.countdownTimer.time()/1000)%60); this.countdownTxt.setText(this.pad(seconds, 2) + ":" + milliseconds); this.countdownTxt.anchor.x = this.countdownTxt.width / 2; this.countdownTxt.position.set(640, -0.5*(game.system.height - 1920) + 64); } }); }); Quote Link to comment Share on other sites More sharing options...
Wolfsbane Posted September 4, 2018 Share Posted September 4, 2018 // TIMER var milliseconds = parseInt((this.countdownTimer.time()%1000)); // This is your millisecond time.. just divide by 10. So. var milliseconds = parseInt((this.countdownTimer.time()%1000)/10); @NinjadoodleYou mean like this? (You'll still need to pad it, too) Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted September 4, 2018 Author Share Posted September 4, 2018 @Wolfsbane - Thanks heaps, that's perfect! So simple, I don't know what I was trying to do lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.