mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1160 from Kenny2github/patch-1
Round (x position) and (y position) to 8 places
This commit is contained in:
commit
3b49f45b9a
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.
|
||||
* @param {!number} x New X coordinate, in Scratch coordinates.
|
||||
|
@ -250,6 +261,8 @@ class RenderedTarget extends Target {
|
|||
const oldY = this.y;
|
||||
if (this.renderer) {
|
||||
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.y = position[1];
|
||||
|
||||
|
@ -261,8 +274,8 @@ class RenderedTarget extends Target {
|
|||
this.runtime.requestRedraw();
|
||||
}
|
||||
} else {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.x = this._roundCoord(x, 8);
|
||||
this.y = this._roundCoord(y, 8);
|
||||
}
|
||||
this.emit(RenderedTarget.EVENT_TARGET_MOVED, this, oldX, oldY, force);
|
||||
this.runtime.requestTargetsUpdate(this);
|
||||
|
|
Loading…
Reference in a new issue