diff --git a/src/RenderWebGL.js b/src/RenderWebGL.js index 24b4696..eaf7a64 100644 --- a/src/RenderWebGL.js +++ b/src/RenderWebGL.js @@ -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]; } diff --git a/test/integration/scratch-tests/sprite-goes-off-stage.sb2 b/test/integration/scratch-tests/sprite-goes-off-stage.sb2 new file mode 100644 index 0000000..c3a7a05 Binary files /dev/null and b/test/integration/scratch-tests/sprite-goes-off-stage.sb2 differ