npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

2dgameinputs

v1.2.0

Published

a 2d game input handler

Downloads

9

Readme

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.

Contact

email:

website:

  • https://alphayo-the-developer.github.io/