I want to make a timer with a big reset button but I don't know how to get the label node to show the the current value of the timer (n).
I tried to find an answer but with no avail any help would be appreciated.
from scene import *
import sound
import random
import math
import time
A = Action
class MyScene (Scene):
def setup(self):
n = 20
Scene.background_color = 1.0, 1.0, 1.0
self.button = SpriteNode('IMG_4056.PNG')
self.button.position = (512, 400)
self.add_child(self.button)
self.time = LabelNode(str(n), font = ('courier', 50))
self.time.position = (512, 100)
self.add_child(self.time)
self.life = LabelNode("Life", font = ('courier', 50))
self.life.position = (512, 700)
self.add_child(self.life)
pass
def did_change_size(self):
pass
def update(self):
pass
def touch_began(self, touch):
if touch.location in self.life.bbox:
n = 20
while (n >= 0):
self.time.remove_from_parent()
self.time = LabelNode(str(n - 1))
self.add_child(self.time)
time.sleep(1)
pass
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
if __name__ == '__main__':
run(MyScene(), show_fps=True)
Here is a sample implementation of the timer and I hope it helps.