Moved font loading external to Draw call. Should improve performance.

This commit is contained in:
2023-11-20 00:28:59 -05:00
parent a875a4ed57
commit efefb3614b
2 changed files with 11 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ func (sm *ScoreManager) Draw(screen *ebiten.Image) {
//highScoreStr := fmt.Sprintf("High Score: %v", highScore)
levelStr := fmt.Sprintf("Level: %v", geom.CurrentLevel)
face := assets.LoadFontFace("fonts/robot.otf", 12)
face := FaceA //assets.LoadFontFace("fonts/robot.otf", 12)
//draw high score (i.e. best level)
//stringWidth := font.MeasureString(face, highScoreStr).Ceil()
@@ -38,8 +38,17 @@ func (sm *ScoreManager) Draw(screen *ebiten.Image) {
//draw energy at the top
energyStr := fmt.Sprintf("Energy: %v", geom.CurrentEnergy)
face = assets.LoadFontFace("fonts/robot.otf", 20)
face = FaceB // assets.LoadFontFace("fonts/robot.otf", 20)
stringWidth := font.MeasureString(face, energyStr).Ceil()
text.Draw(screen, energyStr, face, w/2-stringWidth/2, geom.ScoreOffset, color.White)
}
var (
FaceA, FaceB font.Face
)
func init() {
FaceA = assets.LoadFontFace("fonts/robot.otf", 12)
FaceB = assets.LoadFontFace("fonts/robot.otf", 20)
}