From 3b55648f60d553fa3a25e2921be2bf98b7652120 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 19 Mar 2019 10:19:23 -0500 Subject: [PATCH] feat: track position change --- packages/entity/traits/positioned.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/entity/traits/positioned.js b/packages/entity/traits/positioned.js index cb6ba3f..cb6dc46 100644 --- a/packages/entity/traits/positioned.js +++ b/packages/entity/traits/positioned.js @@ -28,7 +28,13 @@ class PositionedBase extends Trait { } set position([x, y]) { - this.state = this.state.merge({x, y}); + const positionChanged = x !== entity.x || y !== entity.y; + const lastPosition = entity.position; + this.entity.x = x; + this.entity.y = y; + if (positionChanged) { + this.entity.emit('positionChanged', entity.position, lastPosition); + } } }