← Yop2D

How to make an ON / OFF switch?

Beginner guide · no code

Français · English · Español · Deutsch · Italiano · Português · Русский · 中文 · 日本語 · العربية

ℹ️ For Yop2D Next, the new 2D + 3D version of Yop2D (coming soon). Button and node names are those of Yop2D Next.

🔍 How do I…? All short recipes, with a search

A switch the player taps to turn the music on or off. Its value goes into a variable, and a node chooses what happens next.

You need:

Step 1: the switch

  1. Tap Object → Interface elements → Switch.
  2. Name it musique.
  3. In the Inspector, tap the Settings and style… button, Variable that receives the value (optional) line → New variable…: type son, then close the window.

Step 2: the nodes

  1. Open the Blueprint.
  2. When an interface element changes: Object musique
  3. If a variable…: Variable son, Comparison is at least, Value 1
  4. True output → Play music (Music file : Import or listen to sounds…)
  5. False output → Stop music

The nodes

When an interface element changesmusique
→
If a variable…son · is at least 1
True →
Play music
If a variable…
False →
Stop music

Try it

Tap Play, then the switch: the music starts. Tap it again: it stops.

👉 The switch value can also be read with =musique.progression: 1 for ON, 0 for OFF (see the A slider and its value recipe).