How to Make a Multiplayer Game on iPad | hyperPad Blog
hyperPad

How to Make a Multiplayer Game on iPad

April 16, 2026
hyperPad How-TosMultiplayer
How to Make a Multiplayer Game on iPad

You can make a multiplayer game on iPad with hyperPad. For players sharing one iPad, you build everything with Behaviors in the app. For players on separate devices, you connect your game to a server with hyperPad's Socket.io Behaviors, and the server keeps everyone in sync.

This guide starts by helping you pick the right kind of multiplayer. Then it walks through a complete online example: a two-player game of tag that talks to a Socket.io server running on Node.js.

Making a multiplayer game on iPad with hyperPad

Choose your multiplayer structure

"Multiplayer" covers several different designs. Decide first whether players share one screen, take turns, use controllers, or connect through a server. Each choice changes how you handle input, who owns the game state, and what you need to test.

StructureGood forMain design problem
Shared screenQuick party games on one iPadKeeping touch areas and UI readable for everyone
Pass-and-playTurn-based games like card battles or board gamesHiding private information and changing turns
Connected controllersSimultaneous local playAssigning input and handling disconnects
Online (Socket.io)Players on separate devicesRunning a server, latency, reconnection, and security

For a first multiplayer Project, local play is easier to scope. You can build and test it on one iPad, with no server.

Local play on one iPad

Build one Scene with two player Objects and one shared goal. Give each player a distinct color, a starting position, and a score Attribute.

For controllers, read Controller Event, Assign Controller, and the controller-support tutorial. Check that each input moves only its own player. Then disconnect a controller and reconnect it to see what happens.

For pass-and-play, add an Attribute such as currentPlayer. Every action checks it before changing the board. After a valid move, update the Attribute and the UI so the next player knows it's their turn.

Online play on separate devices

Online play needs a server. hyperPad gives you the Socket.io Client and related Behaviors for talking to it, and the Socket.io setup guide in the documentation covers the basics. You still design the messages, validate what players send, and decide what happens when someone lags or drops out.

Before you build, write down the shared data your game needs. For tag, that's each player's position, score, and who is It. For a turn-based game, it might be the board and whose turn it is. The rest of this guide shows how that data moves between the game and the server.

Design for social play

Players come back to a multiplayer game for the people in it. A few design habits make that time feel good, whichever structure you pick.

  • Start with one small shared space. Design one room or arena before you design a world. Each player should see who else is there, where they are, and what they can do, at a glance.
  • Keep every player in view. Choose a camera and layout where avatars and interactive Objects don't hide behind each other. If players can't see each other, they can't play together.
  • Give players a way to express themselves. Even a prototype can let players pick a color, place an Object or choose a reaction. It gives other players a reason to stop by.
  • Design safety in from the start. Any game where strangers can communicate needs it. Prewritten greetings instead of open chat, reporting and blocking, age requirements, and collecting as little personal information as possible are all practical choices.
  • Make one interaction work locally first. Build a single moment, like walking up to a character and choosing a greeting, with a local character before you add networking. Store simple state, like hasGreeted, in an Attribute so the response can't trigger twice.

Before you start the online tutorial

This tutorial covers advanced features and Behaviors in hyperPad. We strongly recommend working through some other tutorials first and getting comfortable with the app before you continue.

It assumes you know hyperPad's core features and have a basic understanding of written programming, because you'll write JavaScript for the game server. It also assumes some basic networking knowledge, like the difference between a server and its clients.

The goal is to show you what it takes to add online multiplayer, rather than how to build the game itself. You'll see how Socket.io clients and the server relate, and how they talk to each other through the Socket.io Behaviors.

Requirements

To create and host the server, you'll need a computer that can run Node.js (Mac, Windows, and so on). This tutorial covers installing and setting up Node.js. If you host the server on your home network, you'll likely need to change your gateway's port-forwarding settings to accept connections from outside your local network.

We've already made a simple demo game for this tutorial: two players play tag in a small maze. Download the project and open it in hyperPad so you can follow along.

Download the completed hyperPad example project here: Multiplayer tag tutorial.tap

How the example game works

The server handles most of the game's details, such as scoring and game lobbies. The game uses Behaviors to send information to the server and react to what comes back.

Here's the general flow:

1. From the main menu, the game connects to the server and lets the player create or join a game.

a. If they create a game, load the waiting room.

b. If they join a game, load a list of available game rooms.

c. When two players are in a waiting room, the game launches.

2. In a game, the server randomly places the players in one of four areas and makes one of them "It".

a. Tagging the other player randomizes both players' locations, swaps the It status, and adds a point for the player who made the tag.

b. If no one is tagged within a certain time, the server removes 1 point from the player who is It and swaps the It status, then randomly places the players in the spawn zones again.

3. Once a player reaches a certain number of points, the game loads an overlay declaring the winner. Then the players disconnect from the room and return to the main menu.

Part 1: Set up the server

A Socket.io server is a JavaScript application that uses the Socket.io library and listens for player connections. Socket.io is a JavaScript networking library that handles a lot of the hard parts of building a networked application for you.

Download and install Node.js

Go to Node.js and download it onto the computer (Mac, Windows, and so on) you want to host the server on. When the download finishes, run the installer and follow its instructions. You can leave every option at its default. Node.js lets you run JavaScript applications on their own, without a web browser.

Download and run the example server

Next, download this tutorial's Multiplayer Server Example from GitHub:

https://github.com/hyperPad/multiplayerServerExample

Click the green "Code" button and select "Download ZIP". This downloads a copy of the server example's code.

Downloading the multiplayer server example as a ZIP from GitHub

Extract the ZIP. Inside you'll find a few small files. The most important one is "index.js", which is the code for the server. Next, open your command line or terminal inside the server example folder.

Type "npm install", press Enter, and let it run. npm is a package manager. It reads the package.json file and downloads the packages the server needs, including Socket.io.

Running npm install in the terminal

When the command finishes, you have everything you need to run the server. In the terminal, type "node ." and the server will start.

Starting the server with node . in the terminal

Your server is now listening on port 3000 for incoming Socket.io connections.

"node ." runs Node.js in the current directory, where it looks for the directory's index file and runs it. By default, that's the "index.js" JavaScript file. It holds most of the server's code, and we'll walk through it in this tutorial.

Leave the terminal open, because closing it also closes the server. The terminal prints messages when players connect or disconnect, when rooms are created or destroyed, and when other events happen.

Note: To allow connections from outside your home network, you'll likely need to open port 3000 on your home gateway. The steps vary from network to network, but you can usually find a guide by searching online for port forwarding on your modem or router. You may need to stop and restart the Node.js server after you change port-forwarding settings.

Part 2: Connect to the server

Once the server is running, you can connect to it from a hyperPad game. Connecting should be the first thing that happens in your project, whichever Scene you're on, since everything needs to talk to the server. It's best to attach these Behaviors to an Object on the Global Layer so they apply across all Scenes.

Socket.io Client and Connect to Socket Behaviors on the Global Layer

In the example project, the Global Layer "Server" label contains the Behaviors above.

These two Behaviors are all you need to connect to the server. First, under the Custom tab, grab the Socket.io Client Behavior and drop it in. Enter your server's URL in the URL tab of its properties window. In the picture above, our server's URL was "http://192.168.0.191:3000", including the protocol and port. Change this to match your server's URL, or the connection will likely fail when you start the game.

Now the game has the server info, but it still needs to connect. For that, you need the Connect to Socket Behavior. Drop one in, open its properties, select the client in the empty box, and set the Function property to "Connect".

Now, when the project loads, it connects to the server automatically.

Connect to Socket Behavior properties set to Connect

Part 3: Create and join rooms

The next step is to create the game lobbies where players join and play together.

The main menu with buttons to create or find a room

Here's our simple Main Menu screen. Players tap one of the buttons to start a room or look for available rooms.

Creating rooms

Let's look at how the game talks to the server to create a room.

Behaviors that create a room

When the player touches the button, they're prompted to type in a room name. The game emits that name to the server, the server creates the room, and the game loads the waiting room Scene.

From here on, we'll use Emit to Socket a lot, because it's the main way to send data to the server. Think of it as the "online version" of Broadcast Message and Receive Message (Emit to Socket does both at once).

Now we need some code on the server that creates the room when it receives the message from the Emit Behavior.

The createRoom socket event in the server code

socket.on('createRoom', (roomName, callback) => {

This line creates a socket event (as a lambda expression) on the server that listens for Emits with the event 'createRoom'.

The first parameter is the value passed through the Emit to Socket Behavior, in this case the room name the player typed in. Here, we've named that parameter 'roomName'.

The second parameter is a function we call later in the socket event to signal the client. The Emit to Socket Behavior only continues once the server calls the callback function. Here, we've named that parameter 'callback'.

const room = {
  id: uuid(),
  name: roomName,
  sockets: []
};

This creates a structure that holds the key information about a room.

'id' is a unique identifier generated by the utility function 'uuid()'. Later, it lets us pick out this room from a list of many other rooms.

'name' is set to the name the player typed in earlier.

'sockets' starts as an empty array. Later, it keeps track of the player sockets connected to the room.

rooms[room.id] = room;

'rooms' is a global list of the rooms that are currently active. Since we're creating a new room, we store it in the list by its ID.

joinRoom(socket, room);

This calls the global function 'joinRoom' (line 29), which adds the player's socket to the room's 'sockets' array. The player created the room, so this makes them join it, too.

callback();
});

Finally, we call the callback function to tell the client the room was created. That lets Emit to Socket continue, which loads the Waiting Room Scene next. This is also the end of the 'createRoom' socket event.

Joining rooms

Joining rooms works a little differently, because we need to access the information from a different Scene than the button's.

Behaviors for joining rooms on the Global Layer

For joining rooms, we placed the start of our Behaviors on the Global Layer, next to where we connect to the server. That way we can access the information from any Scene, in this case the room list. The button simply loads the player into the room list Scene.

Here's our second Behavior for talking to the server. Think of Socket Event as Receive Message: it only activates once the server broadcasts the set message.

A good way to think about it: Socket Event reacts only to information coming from the server, while Emit to Socket runs in reaction to things that happen locally.

As for the logic, once we connect to the server, we Emit the 'getRoomNames' request to get the names of any available rooms.

Emitting the getRoomNames request

Then we set up a label the player can tap to enter a room.

The Room List Scene

This is our Room List Scene. It loads and displays any available game rooms. Tapping a room name loads the player in. Thanks to the Behaviors we set up earlier, the list automatically loads any open rooms and spawns a label for each room name. If nothing shows up, the Refresh List button repeats the Behaviors to load them again.

Behaviors that build the room list

Behaviors that spawn a label for each room

Here's the logic that sets up the list. We won't go into much detail, since we only want to see how it connects to the server.

It starts with an Emit to Socket Behavior that asks the server for information on available rooms. Next comes a Get Array Value Behavior. All data from the server arrives as an Array, and the information we need is in the first value, so we set Get Array Value to get the value at index 0. From there, the Behaviors extract the data, create a label for each room, and spawn the labels on screen.

Next, let's look at the Object the player taps. In our Scene, it's the label called Room Name.

Behaviors on the Room Name label

This text acts as a button once it spawns, but we still need to attach the ID of the room we want to connect to. To do that, we grab the room ID with the Get Attribute Behavior set to dynamic. Then we emit to the server that we want to join this room, and load the waiting room.

The joinRoom socket event in the server code

socket.on('joinRoom', (roomId, callback) => {

This is the entry point for the socket event 'joinRoom'. The first parameter's value is the ID of the room we want to join, which was emitted to the server. Here, we named the parameter 'roomId'.

const room = rooms[roomId];
joinRoom(socket, room);

Using the roomId from the client, we find the right room on the server. Then we call the global function 'joinRoom' (line 29) with the socket of the player who wants to connect and the room itself. We'll look at the 'joinRoom' function in a moment.

callback();
});

Finally, we call the callback function to tell the client to continue loading the Waiting Room Scene. This is the end of the 'joinRoom' socket event.

So, what's going on in the 'joinRoom' function? Let's take a look.

The joinRoom function in the server code

room.sockets.push(socket);

As mentioned earlier, the 'room.sockets' array keeps track of the sockets connected to a room. This line adds the socket to that array.

socket.join(room.id, () => {
  socket.roomId = room.id;
  console.log(socket.id, "Joined", room.id);
});

This is the call that actually connects the client to a room. First we tell the socket to join a room by its ID. When that's done, the callback runs and attaches the room ID to the socket. Finally, we log to the console that a player has joined a room.

Server console showing a player joining a room

The waiting room

The waiting room is a Scene that holds players while they wait for someone else to join, or for the game to begin.

Behaviors in the Waiting Room Scene

When a player enters the room, the game emits a 'ready' message to the server. Once the server receives two of these, it sends a message that the game is starting ('initGame'). We pick up that message with a Socket Event and load the game level. That's all the Behaviors this Scene needs. If you like, you can add a button that disconnects the player from the room and sends them back to the main menu.

Now let's look at the server code to see what happens on that end.

The ready event in the server code

This is the 'ready' event, called when a client has joined a room and is ready to play.

const room = rooms[socket.roomId];

Since we attached the room ID to the socket, we can get the room and check whether the game can start.

if (room.sockets.length == 2) {

Here we check whether two players are now waiting in the room. Let's say they are, so we continue and start the game.

for (const client of room.sockets) {
  client.emit('initGame');
}

With two players in the room, we loop through each socket and emit the 'initGame' event, so each client loads the Level Scene, as shown earlier.

Part 4: Gameplay

Now for the main part. This is where most of the work goes. Below is the game level we designed for this tutorial.

The maze level for the multiplayer tag game

Before we get into that, though, there's a label titled "Game Logic". Let's open it up and take a look.

Behaviors on the Game Logic label

That's a lot of Behaviors. Don't worry. This is simply how we spawn the players into the game. Let's take a closer look.

Behaviors that start the game and read the server's reply

We start with an Emit to Socket Behavior that tells the server our game has started, using the event 'startGame'. Then we take the first value of the array the server returns and use Get Dictionary Value to grab the Attributes our Object needs. A separate Behavior Tree does the same for the opponent. Finally, we broadcast the message 'init' to the player Object to get things started.

Let's see what happens on the server when we emit the 'startGame' event.

The first half of the startGame event in the server code

The first half of this socket event sets some starting values on each client, then adds every client except the one that emitted the event to the local 'others' array.

The second half of the startGame event in the server code

The second half creates a local dictionary called 'ack'. It holds information about us and about the other client(s). We send that information back to the client by passing 'ack' to the callback function, which becomes the result of the Emit to Socket Behavior that made the call.

After that, a 5-second timeout starts the round, now that everyone has the information they need to play. The 'beginRound' function (line 99) controls some game-specific logic for this project. We won't go into detail, but it handles where to spawn the players, checks scores, and tells the clients who is It.

As mentioned before, the "Game Logic" label sends the 'init' message when everything is ready. Now let's look at the Behaviors on the player Object that receive the 'init' message.

Behavior Trees on the player Object

You can see several Behavior Trees on the player. We'll start with the upper-left tree.

The Behavior Tree that receives the init message

This is the Behavior that starts up almost everything else in the game.

First, it receives the 'init' message from the "Game Logic" label. Then it grabs our Object's server ID, turns on one of our Socket Events, and sets up the game screen so the camera follows our character.

Movement syncing

The Behavior Tree that sends the player's position to the server

This is one of the most important Behaviors. This small tree updates the player's position on the server every time you move the joystick. You've probably noticed it references some dictionary values. Those come from a standalone dictionary Behavior that holds the player's X and Y positions.

Let's look at the 'moved' event on the server.

The moved event in the server code

data = JSON.parse(data);

When a client sends a dictionary to the server, the server has to parse it to read the data easily. That's because hyperPad encodes dictionaries as a JSON structure when it emits them to a server. This line parses the JSON string and stores the dictionary back in the same local 'data' variable.

socket.x = data.x;
socket.y = data.y;

Here, we update the X and Y positions stored on the socket with the new values from the client.

for (const client of room.sockets) {
  if (client == socket) {
    continue;
  }
  client.emit(socket.id, {
    x: socket.x,
    y: socket.y,
    score: socket.score,
    isIt: socket.isIt
  });
}

Next, we loop through all the clients and send them our new position and other details, skipping ourselves (the emitting client doesn't need to know its own position).

The Behavior Tree that controls most of the game

This tree controls most of the game. We use a Socket Event for when the server decides which player is It, which 'beginRound' (line 99) emits on the server.

Then we grab our Object's server ID from the array and use Dictionary Value to break it into the pieces of data it contains. From there, we grab our Score, whether we're It, and our Object's X and Y positions, then apply them to the Object's Attributes. The rest of the Behaviors set up and control the game's UI.

Keep online play smooth

Online games feel laggy when they send more than they need. A few habits help:

  • Sync only what other players need. Tag needs position, score, and It status. It doesn't need every animation frame.
  • Limit how often you send updates. Sending a position on every tiny joystick change adds up fast with more players.
  • Smooth the other player's movement. Move their Object toward the latest position the server sent, instead of jumping it there, to hide small network delays.
  • Let the server decide outcomes. In the example, the server picks who is It and awards points. When both players see the same result from one source, disagreements about a tag can't happen.

Test with real players

Many multiplayer bugs only show up with real players on separate devices. Before you invite friends, run through this checklist:

  • Both players connect and see each other move smoothly.
  • The It switch happens once per tag, not over and over while players overlap.
  • Scores match on both screens at the end of a round.
  • A player can leave mid-round and the server and the other player keep going.
  • A new round starts cleanly with positions and It reset.

Test on a slow connection too, and try turning Wi-Fi off on one iPad in the middle of a round. If something breaks, add console.log lines on the server to see what each client is sending. You can also ask other creators for help on the hyperPad Discord.

Learn more JavaScript and Socket.io

It's hard to teach a scripting language like JavaScript in a single article. If you get stuck, these resources cover writing JavaScript applications with Node.js and Socket.io:

Add one online feature to a game you've made

You now know how the Socket.io Behaviors and a server work together. Pick a game you've already built and give it one small online feature. A high-score Scene is a good choice: connect to your server, request the top 10 scores and player names, and display them. Get that working on two iPads before you try real-time movement.

hyperPad Starter

Make Your First Game on iPad

Start with one free project in hyperPad Starter. Drag, drop, and connect Behaviors to build your game without traditional code.

Try hyperPad Starter

Free to download · One project included