1.0.0 • Published 4 years ago

ngx-gamepad v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

ngx-gamepad

Angular gamecontroller.js wrapper service.

Demo

Getting Started

1. Install packages

npm i ngx-gamepad

2. Import Module

import { NgxGamepadModule } from 'ngx-gamepad';

@NgModule({
  declarations: [AppComponent],
  imports: [
    NgxGamepadModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

3. Include the service

import { GamepadService } from 'ngx-gamepad';

export class AppComponent {

  constructor(
    private gamepad: GamepadService
  ){}

  ngOnInit() {
    this.listenToGamepad();
  }

  private listenToGamepad() {
    this.gamepad.connect()
      .subscribe(() => {

        this.gamepad.after('button0')
          .subscribe(() => ...);

        this.gamepad.after('select')
          .subscribe(() => ...);

        this.gamepad.after('start')
          .subscribe(() => ...);

        this.gamepad.on('right')
          .pipe(bufferCount(10))
          .subscribe(() => ...);

        this.gamepad.on('right0')
          .pipe(bufferCount(10))
          .subscribe(() => ...);

        this.gamepad.on('right1')
          .pipe(bufferCount(10))
          .subscribe(() => ...);
      })
  }

}