Only sending move events if the player actually moved

If the player did not move a pixel (and if it did not change direction), then do not send an event to save bandwidth and processing.
This commit is contained in:
David Négrier 2020-05-04 23:11:59 +02:00
parent b51ce51847
commit 86abdfe30b
2 changed files with 10 additions and 5 deletions

View File

@ -50,7 +50,7 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
stop(){ stop(){
this.setVelocity(0, 0); this.setVelocity(0, 0);
this.play(PlayerAnimationNames.None, true); this.anims.stop();
} }
say(text: string) { say(text: string) {

View File

@ -62,7 +62,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
moveUser(delta: number): void { moveUser(delta: number): void {
//if user client on shift, camera and player speed //if user client on shift, camera and player speed
let haveMove = false;
let direction = null; let direction = null;
let activeEvents = this.userInputManager.getEventListForGameTick(); let activeEvents = this.userInputManager.getEventListForGameTick();
@ -87,12 +86,18 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
} }
if (x !== 0 || y !== 0) { if (x !== 0 || y !== 0) {
this.move(x, y); this.move(x, y);
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
} else { } else {
direction = PlayerAnimationNames.None; if (this.previousMove !== PlayerAnimationNames.None) {
this.stop(); direction = PlayerAnimationNames.None;
this.stop();
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
}
} }
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y}); if (direction !== null) {
this.previousMove = direction;
}
} }
//todo: put this method into the NonPlayer class instead //todo: put this method into the NonPlayer class instead