mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 17:09:50 -05:00
Round (x position) and (y position) to 8 places
This commit is contained in:
parent
8c0f5a71f0
commit
5af6887cfe
1 changed files with 15 additions and 2 deletions
|
@ -237,6 +237,17 @@ class RenderedTarget extends Target {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round a number to n digits
|
||||||
|
* @param {number} value The number to be rounded
|
||||||
|
* @param {number} places The number of decimal places to round to
|
||||||
|
* @return {number} The rounded number
|
||||||
|
*/
|
||||||
|
_roundCoord (value, places) {
|
||||||
|
const power = Math.pow(10, places);
|
||||||
|
return Math.round(value * power) / power;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the X and Y coordinates.
|
* Set the X and Y coordinates.
|
||||||
* @param {!number} x New X coordinate, in Scratch coordinates.
|
* @param {!number} x New X coordinate, in Scratch coordinates.
|
||||||
|
@ -250,6 +261,8 @@ class RenderedTarget extends Target {
|
||||||
const oldY = this.y;
|
const oldY = this.y;
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
const position = this.renderer.getFencedPositionOfDrawable(this.drawableID, [x, y]);
|
const position = this.renderer.getFencedPositionOfDrawable(this.drawableID, [x, y]);
|
||||||
|
position[0] = this._roundCoord(position[0], 8);
|
||||||
|
position[1] = this._roundCoord(position[1], 8);
|
||||||
this.x = position[0];
|
this.x = position[0];
|
||||||
this.y = position[1];
|
this.y = position[1];
|
||||||
|
|
||||||
|
@ -261,8 +274,8 @@ class RenderedTarget extends Target {
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.x = x;
|
this.x = this._roundCoord(x, 8);
|
||||||
this.y = y;
|
this.y = this._roundCoord(y, 8);
|
||||||
}
|
}
|
||||||
this.emit(RenderedTarget.EVENT_TARGET_MOVED, this, oldX, oldY, force);
|
this.emit(RenderedTarget.EVENT_TARGET_MOVED, this, oldX, oldY, force);
|
||||||
this.runtime.requestTargetsUpdate(this);
|
this.runtime.requestTargetsUpdate(this);
|
||||||
|
|
Loading…
Reference in a new issue