edzillion Posted November 10, 2015 Share Posted November 10, 2015 Hi Is it possible to use a Phaser.Timer to update a progressbar?timer1 = game.time.events.loop(Phaser.Timer.SECOND, playerAttack1, this);I need to be able to find out how far through a loop my timer is - something like (sloppy code but you get what I mean):var timeleft = timer1.time.next - timer1.time.start;var progressPercent = timeleft / timer1.time.length;the problem I have is that I am not sure how to get timer1.time.start - I can get the start of the timer, but not the start of the last loop. thanks in advance! Link to comment Share on other sites More sharing options...
edzillion Posted November 11, 2015 Author Share Posted November 11, 2015 ok so I got it working using the game.time and timer.next like so:var n = player.timer1.timer.next;var diff = Math.abs((n - t)-1000);var perc = (diff / 1000);where perc is how far through the current loop the timer is (0 -> 1) my next problem is how to deal with multiple timers: this.timer1 = game.time.events.loop(Phaser.Timer.SECOND, playerAttack1, this); this.timer2 = game.time.events.loop(Phaser.Timer.SECOND*4, playerAttack2, this);timer1.next and timer2.next return the same time. the docs say .next returns the time of the next 'event' so I guess that means any event queued in the timer how can I figure that out on a per timer basis? Link to comment Share on other sites More sharing options...
edzillion Posted November 11, 2015 Author Share Posted November 11, 2015 ok now im doing this: timer = game.time.create(false); ... this.timer1 = timer.add(1000, playerAttack1, this); this.timer1.loop = true; this.timer2 = timer.add(4000, playerAttack2, this); this.timer2.loop = true; now the percentages look good but my callbacks (playerAttack1 etc) are not being called (?) Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 It looks like a context issue. Are you sure it's not : this.timer1 = timer.add(1000, playerAttack1, player);Or maybe : this.timer1 = timer.add(1000, player.playerAttack1, player);Do you have any stack trace in the console? Link to comment Share on other sites More sharing options...
edzillion Posted November 11, 2015 Author Share Posted November 11, 2015 got it. the problem was I needed to start() the timers: this.timer1 = timer.add(1000, playerAttack1, this); this.timer1.loop = true; this.timer1.timer.start(); this.timer2 = timer.add(4000, playerAttack2, this); this.timer2.loop = true; this.timer2.timer.start();the docs need updating! the examples list about five different ways to do this, none of them current. Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 Really? When I look at this example : http://phaser.io/examples/v2/time/custom-timer I clearly see : // Start the timer running - this is important! // It won't start automatically, allowing you to hook it to button events and the like. timer.start(); Link to comment Share on other sites More sharing options...
Recommended Posts