TikTok for Developers

Developer Docs

Last updated November 28, 2026

Web Game Adaptation Examples

These example projects show how existing web games were adapted to run as TikTok mini games. Compare them with your own game while you follow Integrate Your Web Game. Each archive has its own README with build steps, the files that changed, and its limits.

To check your setup with a game that's already a mini game package, start with Catch the Block in the Mini Games Quickstart.

Example

What it shows

Sky Blaster

A Canvas 2D browser game, from source to mini game package, including audio and save changes

DOM Tennis

An HTML and CSS game redrawn with Canvas 2D

Tetris

A Canvas 2D game with HTML controls, composed onto one screen

Space Shooter

A custom JavaScript engine with injected canvas, touch, and audio

Space Invaders

A direct WebGL 2 game with shaders and a score display moved out of HTML

Diagnostic

A check for drawing a Canvas 2D interface over a WebGL scene

Prerequisites

  • A mini game app, a test account, and DevTool. For setup, see the Mini Games Quickstart.
  • The tools each example lists, such as Node.js, Git, Python 3, or FFmpeg

Canvas 2D game: Sky Blaster

This example follows an existing browser game from source to a mini game package. The archive includes the original game source, the adaptation, a build script, and license notices. After you extract it, compare source/src/ttmg-entry.ts and source/src/ttmg-bootstrap.ts with the original web entry. For the audio and save changes, see source/src/game/audio.ts and source/src/game/storage/.

Download sky-blaster-canvas-example.zip. From the archive's parent directory, install the locked dependencies, build the package, and start DevTool:

cd sky-blaster-example/source
npm ci --ignore-scripts
cd ..
sh build-experiment.sh
cd package-next
ttmg dev
  1. Check that package-next/ contains game.js, game.json, project.config.json, and licenses/. Configure DevTool with your own app's client key. Don't upload the original HTML entry or browser build.
  2. In DevTool, run the code precheck, select Client preview, and scan the QR code with a test account. Choose a single-player mode, play a round, and test touch, sound, and saved progress.
  3. Upload the package in DevTool. On the Developer Portal, open Code Version, find the uploaded version under Preview, and scan its QR code. Play the same path again.

For the changed files and troubleshooting, see the archive's README.md. The co-op mode needs a reachable room server and platform configuration. Its default local address doesn't work on a phone.

DOM and CSS game: DOM Tennis

This example rebuilds the DOM and CSS interface of DOM Tennis. Download dom-css-example.zip, then get the original source and build:

git clone https://github.com/raohmaru/DOM-Tennis.git dom-tennis-source
git -C dom-tennis-source checkout b4c44d3142f3d4cd6cf2b38fa1415e11d6017b5c
cd dom-tennis-adaptation
npm ci --ignore-scripts
npm run build

The package is generated in dom-tennis-port/.

Canvas 2D and DOM game: Tetris

This example adapts JavaScript Tetris. Download canvas-dom-example.zip, then get the original source and build:

git clone https://github.com/jakesgordon/javascript-tetris.git tetris-source
git -C tetris-source checkout e5c0c42f7dac0f3514a55eff656c6e22e95d68ed
python3 tetris-build.py

Custom engine: Space Shooter

Download custom-engine-shooter-example.zip. This example requires Node.js, npm, Python 3, and FFmpeg with libmp3lame.

cd custom-engine-shooter
npm ci --ignore-scripts
npm run build
npm run test:platform

Open the native/ directory in DevTool.

WebGL 2 game: Space Invaders

This example adapts Space Invaders WebGL. Download webgl-invaders-example.zip, then get the original source and build:

git clone https://github.com/lluises/space-invaders-webgl.git webgl-invaders-candidate
git -C webgl-invaders-candidate checkout --detach 51054a0bb1af17b8ea5fa9e1db87b408533d3948
cd webgl-invaders-example
python3 build.py

Open the port/ directory in DevTool and configure your app's client key. A successful build doesn't confirm rendering or gameplay on a phone.

This example handles touch end and cancel, but it doesn't register background or foreground listeners. Before you use it as a starting point, use onHide and onShow to connect your game's pause and resume paths. When the game is hidden, release held input and pause the game loop, timers, and audio. When it returns, restore timing and resume once. On each target phone, hold a control while you send the game to the background, return, and check that movement or firing isn't stuck.

Diagnostic: WebGL with a Canvas 2D interface

Use this diagnostic if your browser game draws a Canvas 2D interface over a WebGL scene. It checks one composition path. It doesn't adapt your game.

Create a separate folder with the following game.json and game.js files, and set your client key in the DevTool project configuration.

{"deviceOrientation":"portrait"}
const host = TTMinis.game;
const screen = host.createCanvas();
const gl = screen.getContext('webgl');
if (!gl) throw new Error('WebGL is unavailable');
const info = host.getSystemInfoSync();
screen.width = Math.round(info.windowWidth * (info.pixelRatio || 1));
screen.height = Math.round(info.windowHeight * (info.pixelRatio || 1));

// The second canvas is off-screen; its pixels become the HUD texture.
const hud = host.createCanvas();
hud.width = 256;
hud.height = 128;
const ctx = hud.getContext('2d');
if (!ctx) throw new Error('Off-screen Canvas 2D is unavailable');

function makeShader(type, source) {
  const shader = gl.createShader(type);
  gl.shaderSource(shader, source);
  gl.compileShader(shader);
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(shader));
  return shader;
}
const vertex = makeShader(gl.VERTEX_SHADER,
  'attribute vec2 p; varying vec2 uv; void main(){gl_Position=vec4(p,0.,1.);uv=vec2((p.x+1.)*.5,(1.-p.y)*.5);}');
const fragment = makeShader(gl.FRAGMENT_SHADER,
  'precision mediump float; varying vec2 uv; uniform sampler2D tex; void main(){gl_FragColor=texture2D(tex,uv);}');
const program = gl.createProgram();
gl.attachShader(program, vertex);
gl.attachShader(program, fragment);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(program));

const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
const position = gl.getAttribLocation(program, 'p');
const sampler = gl.getUniformLocation(program, 'tex');
let frame = 0;

function draw() {
  // The blue background stands in for the game's existing WebGL scene.
  gl.viewport(0, 0, screen.width, screen.height);
  gl.clearColor(0, 0, 1, 1);
  gl.clear(gl.COLOR_BUFFER_BIT);

  ctx.clearRect(0, 0, hud.width, hud.height);
  ctx.fillStyle = 'rgba(0,255,0,0.5)';
  ctx.fillRect(128, 64, 128, 64);
  ctx.fillStyle = Math.floor(frame++ / 30) % 2 ? '#ffff00' : '#ff0000';
  ctx.fillRect(0, 0, 128, 64);

  gl.useProgram(program);
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  gl.enableVertexAttribArray(position);
  gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
  gl.activeTexture(gl.TEXTURE0);
  gl.bindTexture(gl.TEXTURE_2D, texture);
  gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, hud);
  const error = gl.getError();
  if (error !== gl.NO_ERROR) throw new Error('HUD texture upload failed: ' + error);
  gl.uniform1i(sampler, 0);
  gl.disable(gl.DEPTH_TEST);
  gl.disable(gl.CULL_FACE);
  gl.enable(gl.BLEND);
  gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  requestAnimationFrame(draw);
}
draw();
  1. Start DevTool from this folder, select Client preview, and scan the QR code with a test account.
  2. Check that the upper-left block alternates between red and yellow, the rest of the background is blue, and the lower-right block is green blended with blue. If the game doesn't open, check the first error in DevTool or vConsole.
  3. Repeat on your target Android and iOS devices.

To connect your game, render the existing WebGL scene first. Draw the interface on the off-screen 2D canvas, upload it to the interface texture, and draw the textured quad after the scene. Replace the colored rectangles with your interface drawing code.

This pass changes WebGL state, including the program, buffer, attributes, texture, viewport, depth, culling, and blending. Restore the state your renderer needs, or bind it again before the next scene draw. Test transparent edges and orientation, and adjust the upload and blend settings if your source uses premultiplied alpha. Route touch coordinates to the interface's own hit tests. Uploading the whole interface texture every frame can be expensive, so measure the real game on target devices.

Compare common adaptation patterns

The following illustrations explain adaptation patterns. They aren't downloadable starter projects.

  • Canvas game: Keep the rules and compatible drawing code, add a mini game entry, and connect platform functions in a small integration module.
Infographic mapping web game features to TikTok Mini Game APIs, with separate checks noted for WebGL and Wasm
  • DOM game: Keep the rules where possible, then rebuild the board, menus, and interaction with Canvas 2D, WebGL, or your framework's UI.
Diagram comparing web and mini game versions of a tile game, with shared logic, Canvas 2D, touch input, and platform storage

Next steps

TikTok for Developers