mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-07-25 13:38:50 -04:00
Use Math.ceil and Math.floor to match Scratch 2 logic
This commit is contained in:
parent
b4f9f28417
commit
c8b9516219
2 changed files with 4 additions and 5 deletions
|
@ -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.
Loading…
Add table
Add a link
Reference in a new issue