Skip to content

Controller Formatting Guide

Grant edited this page Feb 24, 2018 · 7 revisions

Contents:

  • How do controllers work?
  • Creating Controller Elements
    • Button
    • Joystick
    • Directional Pad
    • Text
    • TextInput
  • Placement and spacing
  • Changing controllers

How do controllers work?

When using Totality, you must define what the controller will look like on the user's phone. You do this by creating a GameController object, adding ControllerElement objects to it, and sending it to the Totality server.

ControllerElements include buttons, joysticks, input boxes, and anything that will be visible to the user. Each of these elements is described in detail below. You can add as many elements to your controller as you want.

Each controller element has an ID associated with it (you define this ID when you create the element). You should use a unique ID for each element, otherwise you won't be able to tell where the input data is coming from!

Controller Elements

Button

A button element simulates a simple button on a controller. The button will send a message to the server when it is pressed by the user.

You can add a button to your controller like this:

// First we must create a controller object
GameController controller = new GameController();

// Then we create a button object
// Arguments are id, x, y, width, height
Button button1 = new Button("button1", 0, 0, 1.0f, 1.0f);

// Finally, add the button to the controller
controller.addControllerElement(button1);

Joystick

A joystick element simulates an analog joystick on the controller. The user can move the joystick with their finger or a mouse. The joysticks sends a message whenever its position is changed.

Directional Pad

A directional pad (DPad) is like a joystick, but it only tracks 8 discrete directions.

Text

A text element simply displays a string of text on the controller. The user cannot interact with a text element.

TextInput

A text input element creates a text box where the user can type input.

The text input element cannot detect when a user is done typing. We recommend adding a button for the user to press when they are done.

Placement and spacing

Each controller element has four properties that define how it is placed:

  • x: the horizontal center of the element
  • y: the vertical center of the element
  • width: the width of the element
  • height: the height of the element Each of these properties should be a float value between 0 and 1. The values are relative to the size of the screen.

For example: To center an object on the controller, set x to 0.5 and y to 0.5

To make an element take up 1/3 of the vertical height of the screen, set y to 0.66

Note: Joysticks must be square to function properly. If you create a joystick that is not square, Totality will automatically make it square.

Changing controllers

Totality requires you to define a default controller. This controller will automatically be sent to new users when they connect. Once a user is connected, you can send them different controllers.

To define the default controller, use this method:

Totality.instance.setDefaultController(myControllerObject);

To send a new controller, you will need a GameController object and the UUID of the player you are sending it to. Once you have these, simply call this method:

Totality.instance.sendControllerToPlayer(playerUUID, gameController);

Clone this wiki locally