1
0
Fork 0
tetris-go/engine/render/text.go

37 lines
734 B
Go

package render
import (
"image/color"
rl "github.com/gen2brain/raylib-go/raylib"
)
func DrawText(x, y, size int32, text string, col color.RGBA) {
destRect := rl.Rectangle{
X: float32(x),
Y: float32(y),
Width: float32(size),
Height: float32(size),
}
for _, ch := range text {
if ch == ' ' {
destRect.X += float32(size)
continue
}
tile := font.GetTile(ch)
if tile == nil {
destRect.X += float32(size)
continue
}
rl.DrawTexturePro(texture, tile.GetTexRect(), destRect, rl.Vector2Zero(), 0, col)
destRect.X += float32(size)
}
}
func DrawTextCenter(x, y, size int32, text string, col color.RGBA) {
l := int32(len(text))
x = x - ((size * l) / 2)
DrawText(x, y, size, text, col)
}