The player's draw
event is intended for HUD elements like this, especially the label function. If you want the label to show the value of some variable, like your count of collectibles, you can use some string formatting like this:
label "{variable_name}" at x,y
The slightly more complex part is making it only display some of the time. One way this could be done is to only call label
if some other variable is set to a value of 1
.
if show_hud==1 then
label "{variable_name}" at x,y
end
We're going to make that show_hud
variable only equal 1
on frames where the crank is being turned. To do that, first we should set it to 0
at the beginning of every frame. The game's loop
event is always called first, so in that event handler just add show_hud = 0
.
The player's crank
event will be called on frames where the crank is being rotated, so to that event handler we just add show_hud = 1
. And that's it! Your collectible count will only appear when the crank is being rotated.
You might find this is a little too strict. As an improvement you might change things so show_hud
is assigned a value of, say, 10
in the crank event, and rather than setting it to 0
at the start of every frame you instead decrement the value like show_hud--
if it is greater than 0. Then in the player's draw
event check for show_hud>0
to display the collectible count. Doing this will mean the count stays on screen for 10 frames (half a second) after the crank is rotated, which might look a little nicer and stop it "flickering" if the crank is not being constantly rotated.