Skip to content

Commit

Permalink
animation-events: Use onActivate and onDeactivate for key handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMadDodger committed May 16, 2024
1 parent b645d7e commit a702bf2
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions animation-events/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ import { GunController } from './gun-controller.js';
export class Controls extends Component {
static TypeName = 'controls';

init() {
this.reloadDown = false;
this.drawWeaponDown = false;
this.holsterDown = false;
this.mouseDown = false;
reloadDown = false;
drawWeaponDown = false;
holsterDown = false;
mouseDown = false;

window.addEventListener('keydown', this.press.bind(this));
window.addEventListener('keyup', this.release.bind(this));

const canvas = this.engine.canvas;
canvas.addEventListener('mousedown', this.onMouseDown);
canvas.addEventListener('mouseup', this.onMouseUp);
}
keydownCallback = null;
keyupCallback = null;

onActivate() {
this.keydownCallback = this.press.bind(this);
this.keyupCallback = this.release.bind(this);

window.addEventListener('keydown', this.keydownCallback);
window.addEventListener('keyup', this.keyupCallback);

const canvas = this.engine.canvas;
canvas.addEventListener('mousedown', this.onMouseDown);
canvas.addEventListener('mouseup', this.onMouseUp);
}
onDeactivate() {
window.removeEventListener('keydown', this.keydownCallback);
window.removeEventListener('keyup', this.keyupCallback);

const canvas = this.engine.canvas;
canvas.removeEventListener('mousedown', this.onMouseDown);
canvas.removeEventListener('mouseup', this.onMouseUp);
Expand Down

0 comments on commit a702bf2

Please sign in to comment.