From 92e9cc8bbd8900413c1349139e21ef12a411f684 Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Tue, 19 Nov 2013 14:27:56 +0000 Subject: 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 --- (limited to 'tools.py') 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": -- cgit v0.9.1