Joysticks.js (system script)
From Spheriki
Joysticks.js is a system script by Flikky that enables you to attach multiple map persons to different joysticks.
Contents |
[edit]
Usage
Use this to make the script available in your game: RequireSystemScript("joysticks.js");
Then make sure you set the update script:
SetUpdateScript("UpdateJoysticks()");
And then, instead of AttachInput("player"); attach the joystick
using AttachJoystick(0, "player"); (see below).
[edit]
Variables and functions of joystick.js
- DoesPersonExist(person)
- returns true if a person exists.
- GetNumJoystickPlayers()
- returns the number of attached joysticks.
- IsJoystickAttached(joystick)
- returns true if a joystick is attached. Joystick is a number 0 to 3.
- GetJoystickPerson(joystick)
- returns the name of the person controlled with that joystick.
- BindJoystickButton(joystick, joystick_button, on_press_script, on_release_script)
- binds functions to the joystick buttons.
- UnbindJoystickButton(joystick, joystick_button)
- unbinds the functions to the joystick buttons.
- AttachJoystick(joystick, name)
- attaches a joystick number to a person name.
- DetachJoystick(joystick, name)
- detaches a joystick number to a person name.
- UpdateJoysticks()
- called each frame to recalculate movements and button actions.
- UpdateBindedJoysticks()
- internal function
- UpdatePersonJoysticks()
- internal function
- gBindedJoysticks
- internal variable
- gPersonJoysticks
- internal variable
[edit]
Examples
This example creates two persons and attachs a joystick each. If there's only one joystick present, the example uses Sphere's standard function AttachInput(). Resorting to joysticks.js for single player situations isn't necessary.
RequireSystemScript("joysticks.js"); // This will set the update script to check for joystick input SetUpdateScript("UpdateJoysticks()"); function game() { // Create two persons CreatePerson("player_one", "player1.rss", false); CreatePerson("player_two", "player2.rss", false); // Attach two persons if there's two joysticks... otherwise attach only one. if (GetNumJoysticks() >= 1) { AttachJoystick(0, "player_one"); AttachJoystick(1, "player_two"); // Attach a second joystick like this } else { AttachInput("player_one"); } // Run map engine AttachCamera("player_one"); MapEngine("some_map.rmp", 60); }
[edit]
Notes
- In most (maybe all?) cases, you better use Sphere's standard functions to get joystick support:
- If your game is a single player game, use AttachInput(), which attaches keyboard and joystick 0 to a single person.
- Recent versions of the Sphere API have BindJoystickButton() and UnbindJoystickButton() already implemented.
- For multiplayer games, try using AttachPlayerInput() first.
[edit]

