# Create a speed overlay

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.

```lua
function speedOverlay()
    --Nothing here yet
end

engine.addEventListener("render", speedOverlay)
```

Now for us to render our speed we have to first obtain it.\
The [player](https://docs.anvil.team/namespaces/player) namespace provides a method for this that we can use, called [get2DSpeed](https://docs.anvil.team/namespaces/player#player.get2dspeed).\
Let's plug that into the code we have.

```lua
function speedOverlay()
    local speed = player.get2DSpeed()
end

engine.addEventListener("render", speedOverlay)
```

We want to render this data to the screen, for example to the lower middle of it.\
For anything drawing related the [draw](https://docs.anvil.team/namespaces/draw) namespace provides methods for most primitive shapes and [text](https://docs.anvil.team/namespaces/draw#draw.text-content-pos-color-fontsize-fontname).\
\
The draw\.text method expects arguments that we have to pass, namely:

* <mark style="color:purple;">`content`</mark> - This will be the speed we obtained
* <mark style="color:purple;">`pos`</mark> - For example the lower middle of your screen
* <mark style="color:purple;">`color`</mark> - The color of the speed, as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red
* <mark style="color:purple;">`fontSize`</mark> - The size of the text in pixels
* <mark style="color:purple;">`fontName`</mark> - The name of the [font](https://docs.anvil.team/namespaces/draw#draw.text-content-pos-color-fontsize-fontname)

Let's also `floor` our speed and convert it to a string and save it in another variable:

```lua
function speedOverlay()
    local speed = player.get2DSpeed()
    local speedString = tostring(math.floor(speed))
    draw.text(speedString, Vec2:new(960, 540), Vec4:new(255, 0, 0, 255), 36, "Verdana")
end

engine.addEventListener("render", speedOverlay)
```

The result shoud look similiar to this:

{% embed url="<https://gyazo.com/406a346538f90bb4175af140f7fcafd9>" %}
