borrax
Aug 22, 2021 - 05:44
I wrote a simple solitaire game, everything works, but I would like to include a reset button. My first attempt failed, simply calling run() again did not work. So how to reset a scene?
I wrote a simple solitaire game, everything works, but I would like to include a reset button. My first attempt failed, simply calling run() again did not work. So how to reset a scene?
@borrax Perhaps you could remove all children tree, then call self.setup()
from scene import *
class MyScene (Scene):
def setup(self):
self.background_color = 'midnightblue'
self.ship = SpriteNode('spc:PlayerShip1Orange')
self.ship.position = self.size / 2
self.add_child(self.ship)
def touch_began(self, touch):
# touch top of screen to reset
if touch.location[1] > (ui.get_screen_size()[1]-50):
for child in self.children:
child.remove_from_parent()
self.setup()
return
x, y = touch.location
move_action = Action.move_to(x, y, 0.7, TIMING_SINODIAL)
self.ship.run_action(move_action)
run(MyScene())
@cvp, thanks, that worked.