Back to Blog
Guides

How to Make a Game with AI and Share a Playable Link

Learn how to make a game with AI. Pick a scope, describe the rules, playtest in a live preview, add a leaderboard, and publish a browser game anyone can play.

QWQing Wang
Table of contents

A browser game is a good project for building with AI because you judge the result by playing it. It also exposes problems a static page hides: late controls, a board that overflows a phone, or a leaderboard that accepts any number sent to it.

This guide shows how to make a game with AI in Layerwise, from choosing a scope to sharing a link people can play. The game runs in the browser, so anyone with the link can play it on a computer or phone. For a quick look at what Layerwise builds, see the free AI game maker.

Kart Royale 3D racing game template on a coastal circuit

1. Pick a scope you can finish

A 2D puzzle has little state, usually a board and a score, so you can check its rules one move at a time. A 3D game adds a camera, movement, collisions, lighting, and frame rate, and some failures appear only after minutes of play.

For a first game, choose a 2D loop. For a 3D game, start from a template so the scene and controls already work. Then write down:

  • Core loop: what the player does every few seconds.
  • Win and lose rules: how a round ends.
  • Input: keyboard, mouse, touch, or a combination.
  • Scoring: what earns points and whether scores are saved.

2. Start from a game template or a prompt

The game templates give you a playable starting point:

Kart Royale game template: Drift through corners and charge mini-turbo boosts.
Kart Royale Drift through corners and charge mini-turbo boosts.Play the demoTemplate
Kart Royale game template: Race AI rivals around a coastal circuit.
Kart Royale Race AI rivals around a coastal circuit.Play the demoTemplate
Doodle Shooter game template: Survive enemy waves in a city drawn in ink on notebook paper.
Doodle Shooter Survive enemy waves in a city drawn in ink on notebook paper.Play the demoTemplate
Doodle Shooter game template: Play solo or join an online match for up to 10 players.
Doodle Shooter Play solo or join an online match for up to 10 players.Play the demoTemplate
Saltline game template: Cut three uplinks in a rain-soaked container port.
Saltline Cut three uplinks in a rain-soaked container port.Play the demoTemplate
Sundown Showdown game template: Choose one of four fighters and outlast the closing gas.
Sundown Showdown Choose one of four fighters and outlast the closing gas.Play the demoTemplate
Inkwave game template: Claim turf in 4v4 matches and swim through your own ink.
Inkwave Claim turf in 4v4 matches and swim through your own ink.Play the demoTemplate
2048 game template: Slide and merge tiles with the keyboard or a swipe.
2048 Slide and merge tiles with the keyboard or a swipe.Play the demoTemplate
2048 game template: Signed-in players submit their best run to a Top 100.
2048 Signed-in players submit their best run to a Top 100.Play the demoTemplate

Each template page explains how to copy it with Use this template and make a first change. This guide covers the rest: rules, testing, scores, and publishing.

To start from scratch, install Layerwise, sign in, select a team, and enter your prompt in Describe the app you want to build..., as in the Quick start. Every project includes a database and email sign-in; your game's rules, screens, and score storage still need to be built.

3. Write the core loop and rules into the prompt

"Make a fun puzzle game" leaves the agent to invent the rules and gives you nothing to check. State the loop, the input, how a round ends, and what to leave out:

Build a single-player browser puzzle game on a 6x6 grid of gems in four
colors. The player selects a gem, then an adjacent gem, to swap them. A swap
is allowed only if it lines up three or more matching gems in a row or column.
Matched gems clear, score 10 points each, and the gems above fall to fill the
gap. A round has 20 moves and ends with the final score and a Play again
button. Support mouse, touch, and arrow keys with Enter. No sign-in yet.

Play a round and check each sentence: is an invalid swap rejected, and do chained matches score correctly? Quote any wrong rule in your next message.

The gem puzzle prompt from above, sent in a new conversation. Layerwise plans the rules, then the board appears in the preview beside the chat.

For larger changes, use Plan mode to review the approach first. See the prompting guide and Direct the agent.

4. Change one mechanic at a time

Game systems depend on each other. Change speed, drifting, and items together, and you will not know which one made the race worse. Ask for one mechanic and list what must stay the same:

Add a Time Trial mode the player can choose before a race: three laps with no
AI rivals or items. Show the current and best lap times during the race and
all three lap times at the finish. Keep the existing race mode, kart handling,
drifting, and boosts unchanged.

The agent can check its work in the preview by clicking, typing, and reading console errors. It cannot tell you whether a drift feels too loose, so play the change yourself. Describe what you observe: "the kart slides off the track after every drift" is more useful than "handling feels off."

Play each change in the preview: drag a gem, watch the match clear, and check that the score and move count update.

5. Test controls, phone layout, and performance

Check that arrow keys move the game rather than scroll the page, and that each click or tap lands on the intended target.

The preview's phone width shows whether the board and buttons fit, but a mouse cannot tell you how a swipe feels. Test touch on a real phone after publishing.

For a 3D game, play through the busiest moment, such as a late enemy wave or a full 4v4 match, on the slowest device you plan to support. Then ask for a specific fix:

Later enemy waves drop frames on my laptop. Add a Performance option to the
menu that lowers the render resolution and limits how many enemies can be
active at once. Keep the current graphics and enemy count as the default.

If the preview shows a blank scene, open its console from Preview actions and include the error in your next message. See Build and preview.

Preview header with the page path and the Preview actions menu marked
(1) Go to a page by its path. From Preview actions, (2) open the preview in your browser, (3) switch to a phone width, or (4) show the console. Select the image to view it at full size.

6. Add a leaderboard with sign-in and server-side checks

The 2048 template shows a basic leaderboard structure:

  • At game over or a win, a signed-in player sees Submit to Top 100; a signed-out player sees Sign in to submit.
  • A server function reads the player's session, so a request without a signed-in account is not saved.
  • The server rejects anything but a whole number from zero to a fixed maximum, then saves the score with the player's account in the project database.
  • The Top 100 page reads the highest saved scores, and each player can see their own score history.
  1. Game overA signed-in player chooses Submit to Top 100.{ score: 1240 }
  2. Server functionReads the session and checks the number.Signed inWhole number, 0 to maxOtherwise: rejected, shown in Logs
  3. DatabaseSaves the score with the player’s account.scores
  4. Top 100Reads the highest saved scores.1nova2,1802pixelpete1,5603you1,240
The browser only reports the final number. The server decides who sent it and whether it’s in range before anything reaches the leaderboard.

These checks confirm who submitted a score and that it is in range, not that the player earned it: the browser reports the final number. For a competition, ask for more:

Make Top 100 scores harder to fake. Have the server issue a random seed when a
game starts and use it for new tiles. Send the recorded moves with the score,
replay the game on the server, and save the score only if the replay matches.
Keep a game in progress working after a refresh, and explain rejected scores.

Each submitted game is saved separately, so one player can appear in the Top 100 more than once. Decide whether you want that.

To test, finish a game with two accounts in the preview and submit both scores. Sign out and confirm the submit button becomes a sign-in link. Then open Database in the project sidebar, choose Local, and check the scores table. The database and authentication guides explain both views.

Database browser with the Environment selector, table list, Insert, and Export menu marked
(1) Choose Local or Online, (2) select a table such as scores, then (3) insert a row or (4) export the table. Select the image to view it at full size.

Choose Publish in the preview header, then Publish in the menu. After the first successful release, the menu shows the live URL. Publishing applies your schema to the production database; it does not copy local scores or test accounts.

Publish menu showing the live URL, the Private switch, and the Publish button
The Publish menu shows (1) the live URL to share, (2) the Private switch, and (3) the Publish button. Select the image to view it at full size.

At the live URL, create an account and repeat the checks: a full round, a submitted score, and the Top 100 page. Then play on a real phone.

Private in the Publish menu limits the game to your team. It requires a paid plan, and new projects on paid plans start private, so turn it off before sharing publicly. Add UTM parameters to links you post in different places. See Publish a project.

8. Use analytics and logs to see what players do

In Analytics, Pages shows how visits split between the game and the Top 100, Technology shows whether players use phones, and Sources shows referrers and UTM values.

Pages

/81%
/top-10019%

Technology

Phone63%
Desktop37%

Sources

reddit.com612
x.com431
utm_source=discord241
An illustration of the reports for a published game: how visits split between the game and the Top 100, how many players use phones, and which shared links brought them.

Visit duration counts single-page visits as zero seconds, so a one-page game can show short visits and a high bounce rate even when people play for a long time. To count rounds played, save them in the project database.

When a player reports a missing score, open Logs, choose Online, and filter Status to 4xx or 5xx, or search for the score submission. Several rejected submissions after a release may point to a bug in your checks rather than cheating. See Analytics and Logs.

Logs page with the Environment selector, Time range, Live, and filters marked
(1) Choose Online, (2) select a time range, (3) follow requests live, and (4) filter Status to find rejected score submissions. Select the image to view it at full size.

Start with one loop you can finish, test it with real inputs, and add scores once a round works.

View all posts →