Skip to content

Commit 5186824

Browse files
committed
Merging KeepInFence and Goto calls into a single function call. Removing unnecessary no-op math as pointed out by @towerofnix.
1 parent 2f46f9d commit 5186824

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/Sprite.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -627,18 +627,13 @@ export class Sprite extends SpriteBase {
627627
break;
628628
}
629629
this.direction = this.radToScratch(Math.atan2(dy, dx));
630-
const { x, y } = this.keepInFence(this.x, this.y);
631-
this.goto(x, y);
630+
this.positionInFence();
632631
}
633632

634-
keepInFence(newX, newY) {
633+
positionInFence() {
635634
// https://github.com/LLK/scratch-vm/blob/develop/src/sprites/rendered-target.js#L949
636635
const fence = this.stage.fence;
637636
const bounds = this._project.renderer.getTightBoundingBox(this);
638-
bounds.left += newX - this.x;
639-
bounds.right += newX - this.x;
640-
bounds.top += newY - this.y;
641-
bounds.bottom += newY - this.y;
642637

643638
let dx = 0,
644639
dy = 0;
@@ -654,10 +649,8 @@ export class Sprite extends SpriteBase {
654649
if (bounds.bottom < fence.bottom) {
655650
dy += fence.bottom - bounds.bottom;
656651
}
657-
return {
658-
x: newX + dx,
659-
y: newY + dy
660-
};
652+
653+
this.goto(this.x + dx, this.y + dy);
661654
}
662655

663656
get penDown() {

0 commit comments

Comments
 (0)