Handle positioning bubbles for empty costumes

This commit is contained in:
Paul Kaplan 2018-04-20 10:45:54 -04:00
parent 54d5be8bba
commit 393b5d54df

View file

@ -120,7 +120,19 @@ class Scratch3LooksBlocks {
if (!target.visible) return; if (!target.visible) return;
const bubbleState = this._getBubbleState(target); const bubbleState = this._getBubbleState(target);
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId); const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId);
const targetBounds = target.getBoundsForBubble(); let targetBounds;
try {
targetBounds = target.getBoundsForBubble();
} catch (error_) {
// Bounds calculation could fail (e.g. on empty costumes), in that case
// use the x/y position of the target.
targetBounds = {
left: target.x,
right: target.x,
top: target.y,
bottom: target.y
};
}
const stageBounds = this.runtime.getTargetForStage().getBounds(); const stageBounds = this.runtime.getTargetForStage().getBounds();
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right && if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
(targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit (targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit