Totality is a Java library that allows you to use any smartphone as a video game controller.
Totality hosts a web server on the main machine. Users connect to the server using the web browser on their phone. The server sends a javascript controller to the phone, and listens for input.
-
Download TotalityServer.jar and include it in your project.
-
Create a controller object and define its layout:
//Create a controller
GameController gc = new GameController();
gc.addControllerElement(new TextInput("textInput", 0.5f, 0.2f, 0.3f, 0.1f));
gc.addControllerElement(new Button("playButton", 0.5f, 0.7f, 0.3f, 0.3f));
gc.addControllerElement(new Text("text", 0.5f, .1f, "Enter Name and Press Button", 24));
//Set the default controller for new users
Totality.instance.setDefaultController(gc);
(Need help with this? Check out our controller formatting guide)
- Define what to do when a user connects or disconnects:
Totality.instance.addConnectListener(new ConnectListener()
{
@Override
public void onConnect(UUID uuid)
{
//This is called when a new user connects
//We recommend storing the uuid in a hashmap for easy access
}
});
Totality.instance.addDisconnectListener(new DisconnectListener()
{
@Override
public void onDisconnect(UUID uuid)
{
//This is called when a user disconnects
//We recommend removing the uuid from your hashmap here
}
});
- Define what happens when the user interacts with a specific controller element:
Totality.addDataListener(Button.TYPE, new Listener<Button.DataClass>()
{
@Override
public void onData(UUID uuid, DataClass data)
{
if (data.id.equals("playButton"))
{
Totality.instance.sendControllerToPlayer(uuid, newController);
}
}
});
Totality.addDataListener(TextInput.TYPE, new Listener<TextInput.DataClass>()
{
@Override
public void onData(UUID uuid, TextInput.DataClass data)
{
User u = userMap.get(uuid);
u.name = data.text;
}
});
- Start the totality server with:
Totality.instance.start();
And you're ready to go!
Once your server is up and running, users can connect to it with their smartphones. To do so, simply:
- Connect your phone to the same wifi network that the main computer is connected to.
- Open the web browser on your phone.
- Type in the ip address of the main computer to your search bar (or use a multicast address, if supported).
- Press enter. You should now be connected to the Totality server!
Check out our wiki! If you can't find an answer there, feel free to open an issue.