Use Math.ceil and Math.floor to match Scratch 2 logic
This commit is contained in:
@@ -1316,21 +1316,20 @@ class RenderWebGL extends EventEmitter {
|
||||
|
||||
const dx = x - drawable._position[0];
|
||||
const dy = y - drawable._position[1];
|
||||
|
||||
const aabb = drawable.getFastBounds();
|
||||
const inset = Math.floor(Math.min(aabb.width, aabb.height) / 2);
|
||||
|
||||
const sx = this._xRight - Math.min(FENCE_WIDTH, inset);
|
||||
if (aabb.right + dx < -sx) {
|
||||
x = drawable._position[0] - (sx + aabb.right);
|
||||
x = Math.ceil(drawable._position[0] - (sx + aabb.right));
|
||||
} else if (aabb.left + dx > sx) {
|
||||
x = drawable._position[0] + (sx - aabb.left);
|
||||
x = Math.floor(drawable._position[0] + (sx - aabb.left));
|
||||
}
|
||||
const sy = this._yTop - Math.min(FENCE_WIDTH, inset);
|
||||
if (aabb.top + dy < -sy) {
|
||||
y = drawable._position[1] - (sy + aabb.top);
|
||||
y = Math.ceil(drawable._position[1] - (sy + aabb.top));
|
||||
} else if (aabb.bottom + dy > sy) {
|
||||
y = drawable._position[1] + (sy - aabb.bottom);
|
||||
y = Math.floor(drawable._position[1] + (sy - aabb.bottom));
|
||||
}
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
BIN
test/integration/scratch-tests/sprite-goes-off-stage.sb2
Normal file
BIN
test/integration/scratch-tests/sprite-goes-off-stage.sb2
Normal file
Binary file not shown.
Reference in New Issue
Block a user