Skip to main content
Version: 5.x
Supported on
Snapchat

Turn Based Game

You can find this sample project on Lens Studio Home Page.

The Turn-Based Game sample project demonstrates how to create a simple two-player competitive experience. Players take turns tapping a button as fast as they can before the timer runs out. Each player’s best score across turns is tracked, and the highest score wins.

This project can be used as a starting point for building your own turn-based games by swapping out the scoring mechanic, customizing the UI, or extending the win conditions.

Project Structure

Inside the Scene panel, you’ll find the following setup:

Main Camera

A rendering camera for the 3D scene.

Turn Based Scene Object

Contains the Turn Based Component that manages turns, players, and game state.

Turn Based Component Settings:

  1. Require Turn Submission: Enabled.
  2. User Turn Limit: Enabled (limits users to a maximum number of turns).
  3. Turn Limit: 4.
  4. Game Over Scene Objects: Value 0 -> Game Over Screen.
  5. Print Logs: Enabled (to see logs in the Logger panel).

Turn Based Player Info

Holds two Turn Based Player Info Components, one for each player.

Turn Based Player Info Component Settings:

  1. Turn Based Component: Turn Based.
  2. Target User - User Type: User 1 for the first component, User 2 for the second.
  3. Use Bitmoji Sticker: Enabled.
  4. Sticker Type: Selfie.
  5. Auto Load: Enabled.
  6. Apply Sticker To -> Output Type: Material.

Main Logic

Contains the MainLogic Script which orchestrates the game (turns, scoring, win logic).

Orthographic Camera

Used for 2D UI elements. Its children are:

  1. Game UI
    • Best Score Text.
    • Turn Count Text.
    • Tap Button: contains Tap Button Script and Tap Button Text.
    • Timer: contains the Timer script and Timer Text.
    • Counter.
  2. Turn Based UI
    • Players Cards
    • Game Info: includes the Rules and Guides screen and the Side Button.
    • Snap and Send image.
  3. Game Over Screen
    • Displays the final winner text and a crown icon for the winning player.
  4. Start Screen
    • Intro Card: shown only on the first turn of Player 1.
    • Turn Start Card: shown at the beginning of each subsequent turn.

How Gameplay Works

  1. On the first turn, Player 1 presses the Start Game button to begin.

  2. After clicking the Tap To Start button, a countdown timer starts. Player 1 taps the button as fast as possible until time runs out.

  3. The turn ends automatically when the timer hits 0, and the score is sent via Turn Based.

  4. Player 2 receives the Lens. They see Player 1’s card and score, then press Accept Challenge to start their turn.

  5. After both players finish two turns each, the Game Over Screen appears with the winner’s name and crown.

Script Interface

  • MainLogic.ts: Handles game flow, turn lifecycle, winner calculation, and syncing state via the TurnBased API.

  • TapButton.ts: Detects taps, starts the game on the first tap, and increments the per-turn score.

  • Timer.ts: Manages the countdown timer, starts when the game begins, and signals when a turn ends.

Previewing Your Lens

To preview your Lens on Snapchat, follow the Pairing to Snapchat guide.

Was this page helpful?
Yes
No