Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools.py
diff options
context:
space:
mode:
authorSai Vineet <saivineet89@gmail.com>2013-11-19 14:27:56 (GMT)
committer Sai Vineet <saivineet89@gmail.com>2013-11-19 14:27:56 (GMT)
commit92e9cc8bbd8900413c1349139e21ef12a411f684 (patch)
tree74fd6ab1b98ef99f4182075f3d328dff6f44857c /tools.py
parent2bba12a1f733b975e7f9a6bc48698ad101af5443 (diff)
Add a Clear/Erase All tool
Problem: It is problematic to remove all bodies in the canvas, one by one, to get a clear screen. A clear all tool is certainly needed. Solution: Implement a Clear All tool, which also asks for confirmation before destroying everything. Fixes #1615
Diffstat (limited to 'tools.py')
-rw-r--r--tools.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools.py b/tools.py
index 358e1fe..62aba05 100644
--- a/tools.py
+++ b/tools.py
@@ -49,6 +49,14 @@ class Tool(object):
# Stop/start simulation
toggle = self.game.world.run_physics
self.game.world.run_physics = not toggle
+ elif event.action == "clear_all":
+ if len(self.game.world.world.GetBodyList()) > 1:
+ # Get bodies and destroy them too
+ for body in self.game.world.world.GetBodyList():
+ self.game.world.world.DestroyBody(body)
+
+ # Add ground, because we destroyed it before
+ self.game.world.add.ground()
elif event.action == "focus_in":
self.game.in_focus = True
elif event.action == "focus_out":