feat: track position change

This commit is contained in:
cha0s 2019-03-19 10:19:23 -05:00
parent 701623ea31
commit 3b55648f60

View File

@ -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);
}
}
}