mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Fix issue where say bubble flickers during conversation.
The fix for this involves something of hack where we decide whether to use the optimization that prevents "typewriter" style projects (say for 0.05s in a loop) based on the amount of time the block is going to run for. A full fix of this can only be achieved if the text bubble renders synchronously.
This commit is contained in:
parent
50708c15e4
commit
3019d05181
1 changed files with 20 additions and 2 deletions
|
@ -58,6 +58,14 @@ class Scratch3LooksBlocks {
|
|||
return 'Scratch.looks';
|
||||
}
|
||||
|
||||
/**
|
||||
* Max block time we use the "soft clear" optimization to prevent flickering in "typewriter" projects.
|
||||
* @type {string}
|
||||
*/
|
||||
static get MAX_SOFT_CLEAR_TIME () {
|
||||
return 0.02; // seconds
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Target} target - collect bubble state for this target. Probably, but not necessarily, a RenderedTarget.
|
||||
* @returns {BubbleState} the mutable bubble state associated with that target. This will be created if necessary.
|
||||
|
@ -282,12 +290,17 @@ class Scratch3LooksBlocks {
|
|||
this.say(args, util);
|
||||
const target = util.target;
|
||||
const usageId = this._getBubbleState(target).usageId;
|
||||
const secs = args.SECS;
|
||||
return new Promise(resolve => {
|
||||
this._bubbleTimeout = setTimeout(() => {
|
||||
this._bubbleTimeout = null;
|
||||
// Clear say bubble if it hasn't been changed and proceed.
|
||||
if (this._getBubbleState(target).usageId === usageId) {
|
||||
this._updateBubble(target, 'say', '');
|
||||
if (secs < this.MAX_SOFT_CLEAR_TIME) {
|
||||
this._updateBubble(target, 'say', '');
|
||||
} else {
|
||||
this._onTargetWillExit(target);
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
}, 1000 * args.SECS);
|
||||
|
@ -302,12 +315,17 @@ class Scratch3LooksBlocks {
|
|||
this.think(args, util);
|
||||
const target = util.target;
|
||||
const usageId = this._getBubbleState(target).usageId;
|
||||
const secs = args.SECS;
|
||||
return new Promise(resolve => {
|
||||
this._bubbleTimeout = setTimeout(() => {
|
||||
this._bubbleTimeout = null;
|
||||
// Clear think bubble if it hasn't been changed and proceed.
|
||||
if (this._getBubbleState(target).usageId === usageId) {
|
||||
this._updateBubble(target, 'think', '');
|
||||
if (secs < this.MAX_SOFT_CLEAR_TIME) {
|
||||
this._updateBubble(target, 'think', '');
|
||||
} else {
|
||||
this._onTargetWillExit(target);
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
}, 1000 * args.SECS);
|
||||
|
|
Loading…
Reference in a new issue