leopard-js / leopard

Library for making Scratch-like projects with JavaScript.
https://leopardjs.com
MIT License
136 stars 24 forks source link

Investigate and match Scratch's timer implementation #180

Open towerofnix opened 1 year ago

towerofnix commented 1 year ago

The current timer implementation in Leopard is very rudimentary:

https://github.com/leopard-js/leopard/blob/25652b187ab1f5876844316a8e7ba492e4891319/src/Project.js#L251-L254

This would be quite dandy if that's how the timer worked in Scratch, too, but it's not 📦

See this project I made last year which shows that the timer block is only updated once every rendered Scratch frame. (The main project loop runs many times in one frame unless you click "simulate movement", which enables requesting a screen redraw every tick.)

See all the gruesome details in scratch-vm: clock.js, sequencer.js.

another-m00 commented 1 year ago

Related Timer implementation is Scratch-vm

another-m00 commented 1 year ago

It appears that the timer itself was implemented pretty similarly, except they used this date method as fallback for the performance counter