Create a speed overlay
Last updated
Last updated
In this small example we will create a text overlay that will display your current 2D speed. First lets make sure the code we will write will be called every frame and thus update the display correctly.
Now for us to render our speed we have to first obtain it. The namespace provides a method for this that we can use, called . Let's plug that into the code we have.
We want to render this data to the screen, for example to the lower middle of it. For anything drawing related the namespace provides methods for most primitive shapes and . The draw.text method expects arguments that we have to pass, namely:
content
- This will be the speed we obtained
pos
- For example the lower middle of your screen
color
- The color of the speed, as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red
fontSize
- The size of the text in pixels
fontName
- The name of the
Let's also floor
our speed and convert it to a string and save it in another variable:
The result shoud look similiar to this: