mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #593 from fsih/fixWaitCalledEveryFrame
Change wait to use a promise instead of being called every frame
This commit is contained in:
commit
fb986effe6
1 changed files with 7 additions and 13 deletions
|
@ -1,5 +1,4 @@
|
||||||
const Cast = require('../util/cast');
|
const Cast = require('../util/cast');
|
||||||
const Timer = require('../util/timer');
|
|
||||||
|
|
||||||
class Scratch3ControlBlocks {
|
class Scratch3ControlBlocks {
|
||||||
constructor (runtime) {
|
constructor (runtime) {
|
||||||
|
@ -73,18 +72,13 @@ class Scratch3ControlBlocks {
|
||||||
util.startBranch(1, true);
|
util.startBranch(1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
wait (args, util) {
|
wait (args) {
|
||||||
if (!util.stackFrame.timer) {
|
const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
|
||||||
util.stackFrame.timer = new Timer();
|
return new Promise(resolve => {
|
||||||
util.stackFrame.timer.start();
|
setTimeout(() => {
|
||||||
util.yield();
|
resolve();
|
||||||
this.runtime.requestRedraw();
|
}, duration);
|
||||||
} else {
|
});
|
||||||
const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
|
|
||||||
if (util.stackFrame.timer.timeElapsed() < duration) {
|
|
||||||
util.yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args, util) {
|
if (args, util) {
|
||||||
|
|
Loading…
Reference in a new issue