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