AndrewC Posted September 29, 2017 Share Posted September 29, 2017 Hi All, I've seen discussions about the use of timers for control of timed repetition, and examples that use Phaser.time as well as others that use the setInterval mechanism. My question is - is there a best practice recommendation on which way is better? In my situation, I require the use of intervals in order to move a character sprite along a predefined path (generated by A*). There appear to be a number of different ways to do this, and the interpolation function popped up during my research as well. I'm keen to find out the trade offs and decision making involved by folks, and whether there is a recognised or standard best way to do it. Kind Regards, Andrew. Link to comment Share on other sites More sharing options...
AndrewC Posted September 29, 2017 Author Share Posted September 29, 2017 Update: I may have partially answered my own question, after finding this comment on StackOverflow by Matthew Cooley: "the reason to not use the native setTimeout in Phaser is that Phaser's timers are tied to its game loop, so for example if you pause the game it pauses all the timers automatically" https://stackoverflow.com/questions/26319846/how-to-delay-the-start-time-of-a-timer-in-javascript-phaser Would love to hear any further wisdom that folks could share. Link to comment Share on other sites More sharing options...
samid737 Posted September 30, 2017 Share Posted September 30, 2017 For paths you can use tweens . The advantage is that you can specifiy the type of motion using easing functions , (a list) and you can specify the interpolation method to use if you have an array of points,. For timed events (score update, spawning) you can indeed use Phaser.Timer. Link to comment Share on other sites More sharing options...
samme Posted September 30, 2017 Share Posted September 30, 2017 I don't think there's any good reason to use setInterval once the game loop is running. Link to comment Share on other sites More sharing options...
Recommended Posts