Giter VIP home page Giter VIP logo

controllerly's Introduction

npm version Build Status dependencies Status devDependencies Status Known Vulnerabilities NPM

Controllerly

Optimized Smartphone Gamepad Enabling Your Local Multiplayer Games.

Easy integration into your new and existing games.

Add to HTML

<script src="https://cdn.jsdelivr.net/npm/controllerly@latest"></script>
<script>
    // Controllery is exposed as a global variable
    console.log(Controllerly.version);
    // you can map certain gamepad keys to keyboard events
    Controllerly.putKeyboardMapping(0, { // '0' is the first controller
        left: 'A',
        right: 'D',
        start: 'ENTER',
        a: 'Q',
        b: 'W'
    });
    // preview the connection code with an alert
    // the alert dismisses automatically if a client connects
    Controllerly.showConnectionCodeAlert();
</script>

You can also directly map to the native WebGamepad API. However, you should not provide keyboard mappings and use the GamepadAPI at the same time.

// map onto native Gamepad API
Controllerly.enableGamepadAPI();

Install via npm

For a direct game integration you can add Controllerly directly to your project or game.

npm install controllerly

Use with Typescript

// import Controllerly instance
// the same instance is available globally
import Controllerly from 'controllerly';

Gamepad Layout Templates

Use unique gamepad layouts that fit your game or project.

Controllerly.changeLayout('classic');

Layouts define ids for the input controls like buttons. For the classic layout they are:

left, right
start, select
a, b

TODO insert pic

The left and right area are the major areas. On small devices the user has the option to hide the center (green). He then has to open the center through an extra button.

Using Advanced Input Events

To get the most out of your smartphone controlled gamepad, Controllerly provides the option to react to double taps or swipes.

You have the following options:

// basics
active
inactive

// taps
tap
longPress

// swipes
swipeUp
swipeLeft
swipeRight
swipeDown

In your code you can then listen by writing

Controllerly.on('b_longPress');

If you map keyboard events you extend the button name with the input action.

Controllerly.putKeyboardMapping(0, {
    left_tap: 'A',
    right_doubleTap: 'D',
    start_longPress: 'ENTER',
    a: 'E',
    a_swipeUp: 'Q'
});

FAQ

How do I create my own Controllerly instance?

// if you prefer creating your own instance use
import { ControllerlyAPI } from 'controllerly/lib/Controllerly';
let controllerly = new ControllerlyAPI();
// however, this is not recommended because Controllerly creates
// one new WebRTC connection for each instance

Three Controllerly Packages

The project addresses three main concerns regarding remote smartphone gamepads through WebRTC:

Controllerly Packages

Controllerly Server (This Repository)

Controllerly Core

Controllerly Client

Server

The server lives on the game-side. It manages game integration and offers an API to integrate Controllerly into your games.

Core

Client

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.