nodes/hud.pyΒΆ
Part of Clumsy Bird.
1"""Score HUD: anchored Label that displays the current score."""
2
3from simvx.core import Vec2
4from simvx.core.ui import Anchor, Control, Label, PointerFilter
5
6
7class ScoreHUD(Control):
8 """Big centred score readout, anchored to the top-centre of the viewport.
9
10 A readout, not a control: it and its label ignore the pointer so a tap
11 that lands on the score still flaps the bird.
12 """
13
14 def __init__(self, **kwargs):
15 super().__init__(**kwargs)
16 self.anchor = Anchor.TOP_WIDE
17 self.size = Vec2(0, 100) # width is anchored full-width
18 self.pointer_filter = PointerFilter.IGNORE
19
20 self.label = self.add_child(Label("0", name="ScoreLabel", anchor=Anchor.FULL_RECT, inset=(0, 18, 0, 0)))
21 self.label.pointer_filter = PointerFilter.IGNORE
22 self.label.font_size = 64
23 self.label.alignment = "centre"
24 self.label.text_colour = (1.0, 1.0, 1.0, 1.0)
25
26 def set_score(self, score: int):
27 self.label.text = str(score)