16

16 - Score#

Let's add a score to count how many pipes the bird managed to fly past.

In the Level Sprite we add a score field to the state and increment it whenever we pass a pipe. Then we render it in the top-left corner with a t.text Texture.

Notice the align field of the font prop on the text Texture: by default, Sprites have an anchor point in their center, which defines how they're positioned and rotate. Setting align: "left" moves the left edge of the text to the Sprite's anchor point, providing a left text align for the score. The x position of the Texture is now the left side of it, not the center.