← Yop2D

How to have 3 lives?

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

The hero has 3 lives, shown on screen. When it touches an enemy, it loses a life and blinks. At 0, the scene starts over.

You need:

Step 1: the vies variable

  1. Left panel, Scene tab, GAME VARIABLES section: tap New variable. Name (no spaces): vies; Type: Whole number; Starting value: 3. Then Apply.

Step 2: the lives text

  1. Tap Object → Texts → Text.
  2. Name it vies_label and type 3 in its Text line.

Step 3: the hero and the enemy

  1. Put an object in the scene (an image or a Square) and name it heros.
  2. Select heros, tap ⚙ Object behavior in the Inspector and choose Top-down character.
  3. Tap Object → Interactive → Joystick.
  4. Put an object in the scene (an image or a Square) and name it ennemi.
  5. In the Inspector, Tag (family of objects) line, type ennemi.

Step 4: the nodes

  1. Open the Blueprint.
  2. If object touches Tag: Object heros, Tag (family of objects touched) ennemi
  3. Add to Variable: Variable vies, Value to add -1
  4. Modify Text: Object vies_label, New text =vies
  5. Blink: Object heros, Duration (milliseconds, 0 = endless) 1500
  6. If a variable…: Variable vies, Comparison is at most, Value 0
  7. True output → Modify Variable (Variable vies, Value 3) → Restart the scene

The nodes

If object touches Tagheros · ennemi
→
Add to Variablevies · -1
→
Modify Text=vies
→
Blinkheros · 1500
→
If a variable…vies · is at most 0
If a variable…
True →
Modify Variablevies · 3
→
Restart the scene

Try it

Tap Play and touch the enemy: the number goes down and the hero blinks. At 0, everything starts over with 3 lives.

👉 For a real end screen, replace Restart the scene with Go to scene (see the A “Game over” screen recipe).