round x and y like Scratch 2 does

https://github.com/LLK/scratch-flash/blob/develop/src/scratch/ScratchSprite.as#L180-L186

Scratch 2 rounds the X and Y to the nearest whole number.
This commit is contained in:
Michael "Z" Goddard 2018-08-13 14:53:00 -04:00
parent 9bfce505f1
commit f1fce036f0
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -272,8 +272,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[0] = Math.round(position[0]);
position[1] = this._roundCoord(position[1], 8); position[1] = Math.round(position[1]);
this.x = position[0]; this.x = position[0];
this.y = position[1]; this.y = position[1];
@ -285,8 +285,8 @@ class RenderedTarget extends Target {
this.runtime.requestRedraw(); this.runtime.requestRedraw();
} }
} else { } else {
this.x = this._roundCoord(x, 8); this.x = Math.round(x);
this.y = this._roundCoord(y, 8); this.y = Math.round(y);
} }
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);