Skip to content

Commit

Permalink
fix: bug for joystick deltaZ
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Apr 7, 2021
1 parent 7523758 commit 41cd561
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/xkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class XKeys extends EventEmitter {
const emitValue: JoystickValueEmit = {
...newValue,
// Calculate deltaZ, since that is not trivial to do:
deltaZ: XKeys.calculateDelta(newValue.z, oldValue.z, 255),
deltaZ: XKeys.calculateDelta(newValue.z, oldValue.z),
}
this.emit('joystick', index, emitValue, eventMetadata)
}
Expand Down Expand Up @@ -753,7 +753,7 @@ export class XKeys extends EventEmitter {
if (!this._initialized) throw new Error('XKeys.init() must be run first!')
}
/** Calcuate delta value */
static calculateDelta(newValue: number, oldValue: number, overflow: number = 256): number {
static calculateDelta(newValue: number, oldValue: number, overflow = 256): number {
let delta = newValue - oldValue
if (delta < -overflow * 0.5) delta += overflow // Deal with when the new value overflows
if (delta > overflow * 0.5) delta -= overflow // Deal with when the new value underflows
Expand Down

0 comments on commit 41cd561

Please sign in to comment.