tempneff

Stopwatch

Jun 25th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var config = {
  2.     type: Phaser.AUTO,
  3.     backgroundColor: '#363742',
  4.     scale:{
  5.     mode: Phaser.Scale.FIT,
  6.     autoCenter: Phaser.Scale.CENTER_BOTH,
  7.     width: 800,
  8.     height: 600,
  9.     },
  10.  
  11.     parent: 'phaser-example',
  12.  
  13.     scene: {
  14.         create: create,
  15.         update: update,
  16.         physics: {
  17.             matter: {
  18.                 debug: false,
  19.                 gravity: { y:0, x:0 }//1.8 for 10ft .433 for 5m
  20.             }
  21.         }
  22.     }
  23. };
  24.  
  25.  
  26. var game = new Phaser.Game(config);
  27. var timedEvent;
  28. var output;
  29.  
  30. function create ()
  31. {
  32.     timedEvent = this.time.addEvent({ delay: 1, callback: timeR, callbackScope: this, loop: true,paused:true});
  33.     this.add.text(300, 300, "START").setInteractive().on('pointerdown',function(pointer){start();},this);;
  34.     this.add.text(400, 300, "RESET").setInteractive().on('pointerdown',function(pointer){reset(this);},this);;
  35.     output = this.add.text(350, 250, "0.000");
  36.    
  37. }
  38. function update()
  39. {
  40.     timeout = (timedEvent.getProgress()/1000).toFixed(3);
  41.     output.setText(timeout);
  42.    
  43. }
  44.  
  45. function timeR(){}
  46.  
  47. function start(){
  48.     if(timedEvent.paused){
  49.     timedEvent.paused = false;
  50.     console.log('unpaused')}
  51.     else{
  52.     timedEvent.paused=true;
  53.     console.log('paused')
  54.     }
  55. }
  56. function reset(scope){
  57.     timedEvent.reset();
  58.     timedEvent = scope.time.addEvent({ delay: 1, callback: timeR, callbackScope: this, loop: true, paused:true});
  59. }
Add Comment
Please, Sign In to add comment