mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Update repeat implementation to execute once per frame
This commit is contained in:
parent
de6ba08866
commit
39c71b559d
1 changed files with 17 additions and 5 deletions
|
@ -28,15 +28,27 @@ Scratch3ControlBlocks.prototype.repeat = function(args, util) {
|
|||
if (util.stackFrame.loopCounter === undefined) {
|
||||
util.stackFrame.loopCounter = parseInt(args.TIMES);
|
||||
}
|
||||
// Decrease counter
|
||||
util.stackFrame.loopCounter--;
|
||||
// If we still have some left, start the substack
|
||||
if (util.stackFrame.loopCounter >= 0) {
|
||||
util.startSubstack();
|
||||
// Only execute once per frame.
|
||||
// When the substack finishes, `repeat` will be executed again and
|
||||
// the second branch will be taken, yielding for the rest of the frame.
|
||||
if (!util.stackFrame.executed) {
|
||||
util.stackFrame.executed = true;
|
||||
// Decrease counter
|
||||
util.stackFrame.loopCounter--;
|
||||
// If we still have some left, start the substack
|
||||
if (util.stackFrame.loopCounter >= 0) {
|
||||
util.startSubstack();
|
||||
}
|
||||
} else {
|
||||
util.stackFrame.executed = false;
|
||||
util.yieldFrame();
|
||||
}
|
||||
};
|
||||
|
||||
Scratch3ControlBlocks.prototype.forever = function(args, util) {
|
||||
// Only execute once per frame.
|
||||
// When the substack finishes, `forever` will be executed again and
|
||||
// the second branch will be taken, yielding for the rest of the frame.
|
||||
if (!util.stackFrame.executed) {
|
||||
util.stackFrame.executed = true;
|
||||
util.startSubstack();
|
||||
|
|
Loading…
Reference in a new issue