I have the code to keep a current score while playing a game, but how do you draw a simple box, perhaps with or without a texture, like a board, with the “score: x” (“x” being your current score, don’t worry about all that.)
Here’s the code for the scoring…
I would like the box to be centralized around the “score” text, and where it is positioned.
And I’m sorry for coming off like I don’t have a clue, but I’m still warming up to the draw functions…
I believe textMode and textAlign is center by default, so no need for that code.
In setup() do rectMode(CENTER), then you can place it at same coordinates at the text. Draw it before the text so it is behind it.
In draw if you wanted a simple rectangle behind the score, you just use rect(x,y,w,h).
If you have an image you want to use for the background of the score, use sprite(object,x,y,w,h)
But it’s only default for the first time the main draw loop is run. Then it’s whatever the current setting is
You can use
w, h = textSize("Sample Text") to get the size of text (make sure to call it AFTER all the font()s and fontSize()s). Then you could try use textMode(CORNER), and have the X and Y be WIDTH - w, HEIGHT - h (w, h being text size)
Edit: here you go:
local w, h = textSize("Score: "..score)
background(40, 40, 50)
-- draw rect
stroke(255, 9, 0, 255)
fill(0, 8, 255, 255)
-- draw score