Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

2dgameinputs

a 2d game input handler

Published8 Apr 2024
Direct dependencies0
Transitive dependenciesNot calculated

README

Current package documentation

MIT License LinkedIn

About The Project

Markdown Logo

When you want to quckly add Game Inputs in your javascript game.

It supports the following inputs :

  • Keyboard press
  • Button touch
  • TouchScreen swipes
  • Virtual Joystick

Getting Started

Use the following url to download the library from a CDN.

 https://unpkg.com/2dgameinputs/InputHandler.js

Usage :

1. joystick

  • import the JOYSTICK class
  import { JOYSTICK } from "https://unpkg.com/2dgameinputs/InputHandler.js";
  • create an instance of the JOYSTIC class.
  var joystick = new JOYSTICK();
  • The instance has a 'controller' property which has a 'value' property.

    console.log(joystick.controller.value);
    
  • This property is a vector with an 'x'and 'y' , each with a value ranging from -1 to 1.

    
      "x": 0,
      "y": 0
    
    

    example:

    move player to the right and left.

    function gameLoop(){
      if( joystick.controller.value.x > 0){
        player.position.x++
      }
    
      if( joystick.controller.value.x < 0){
        player.position.x--
      }
    }
    
    

2. button

  • import the BUTTON class
  import { BUTTON } from "https://unpkg.com/2dgameinputs/InputHandler.js";
  • create an instance of the BUTTON class that takes an element id as its only parameter.
  var hitbtn = new BUTTON('btn');
  • The instance has a 'pressed' property that is a boolean value.

    console.log(hitbtn);
    
  • This property is TRUE when the element is pressed and FALSE otherwise.

    example:

    a jump button

    function gameLoop(){
      if( hitbtn){
        player.position.y++
      }
    
    }
    
    

3. keyboard press

  • import the INPUTHANDLER class
  import { INPUTHANDLER } from "https://unpkg.com/2dgameinputs/InputHandler.js";
  • create an instance of the INPUTHANDLER class.
  const inputHandler = new INPUTHANDLER();
  • The instance has a 'addkeys' method that accepts a string (HTML keys) .

    inputHandler.addkeys('a')
    inputHandler.addkeys('d')
    
  • The instance has a 'getKey' method that returns a boolean value.

    let a = inputHandler.getKey('a');
    
    let d = inputHandler.getKey('d');
    

    example:

    move player to the right and left.

    function gameLoop(){
      if( d){
        player.position.x++
      }
    
      if( a){
        player.position.x--
      }
    }
    
    

3. touchscreen swipe

  • import the SWIPE class
  import { SWIPE } from "https://unpkg.com/2dgameinputs/InputHandler.js";
  • create an instance of the SWIPE class.
  var swipe = new SWIPE();
  • The instance has four methods that each returns a boolean value .

    let swipeDown = swipe.swipeDown()
    let swiperight = swipe.swipeRight()
    let swipeleft = swipe.swipeLeft()
    let swipeup = swipe.swipeUp()
    

    example:

    move player to the right and left.

    function gameLoop(){
      if( swiperight){
        player.position.x++
      }
    
      if(swipeleft){
        player.position.x--
      }
    }
    
    

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

email:

website:

(back to top)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-DQAR9sCFecJ8ojns5gqOmlq9mil3LMoze3yHMl2Fvm3tGLcmrxY27krlG9dGpZtUf7H/eokt+Jw9KZnt7ShuAg==",
  "shasum": "c85575205d58cf6d114a670f54b04ea494f2e88d",
  "tarball": "https://registry.npmjs.org/2dgameinputs/-/2dgameinputs-1.0.0.tgz",
  "fileCount": 2,
  "unpackedSize": 12140,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQDHCPPb3rVmI91qlv+DRWOdXE8Swz0Oli7UbXOhMEK1FAIhAJqk9e9NNLKg9+12vGjfEWTbekxcNjfc9QlUZFtcGeR2"
    }
  ]
}

Repository

PENDING
alphayo-the-developer/inputhandler

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:11 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f7e8ed9fcdb5985ea0694ea46416f545ce9cb9ea27caa641b3600a22a4333cfb

Other collected versions

1.2.08 Apr1.1.08 AprView all collected versions →