ℹ️ 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 health bar that goes down when the player loses health. When health reaches 0, the scene restarts. To try it, a -10 button removes health.
You need:
- a 2D project open in Yop2D Next.
Step 1: the vie variable
- Left panel, Scene tab, GAME VARIABLES section: tap New variable. Name (no spaces): vie; Type: Whole number; Starting value: 100. Then Apply.
Step 2: the bar
- Tap Object → Interface (HUD) → Progress bar.
- Name it vie_barre.
- In the Inspector: Minimum value 0, Maximum value 100, Starting value 100.
Step 3: a button to try it
- Tap Object → Interactive → Button with text.
- Name it aie and type -10 in its Text line.
Step 4: the nodes
- Open the Blueprint.
- On Object Click: Object aie
- Add to Variable: Variable vie, Value to add -10
- Set Progress: Object vie_barre, New progress
=vie - If a variable…: Variable vie, Comparison is at most, Value 0
- True output → Modify Variable (Variable vie, Value 100) → Restart the scene
The nodes
On Object Clickaie
→
Add to Variablevie · -10
→
Set Progressvie_barre · =vie
If a variable…vie · is at most 0
True →
Modify Variablevie · 100
→
Restart the scene
Try it
Tap Play, then -10 several times: the bar goes down. At 0, the scene restarts with a full bar.
⚠️ Restart the scene does not reset the game variables to their starting value: that's why Modify Variable sets vie back to 100 just before.
👉 For a real game: replace On Object Click with If object touches Tag (the hero touches an enemy).