Moved font loading external to Draw call. Should improve performance.
This commit is contained in:
@@ -96,7 +96,6 @@ func BuildGrid(numRows int, numColumns int) {
|
|||||||
|
|
||||||
//assign random colours to a subset of all squares
|
//assign random colours to a subset of all squares
|
||||||
squaresToColour := min(numColumns, numRows)
|
squaresToColour := min(numColumns, numRows)
|
||||||
|
|
||||||
usedPositions := make([]Pair, squaresToColour)
|
usedPositions := make([]Pair, squaresToColour)
|
||||||
coloredSoFar := 0
|
coloredSoFar := 0
|
||||||
for i := 0; i < squaresToColour; i++ {
|
for i := 0; i < squaresToColour; i++ {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (sm *ScoreManager) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
//highScoreStr := fmt.Sprintf("High Score: %v", highScore)
|
//highScoreStr := fmt.Sprintf("High Score: %v", highScore)
|
||||||
levelStr := fmt.Sprintf("Level: %v", geom.CurrentLevel)
|
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)
|
//draw high score (i.e. best level)
|
||||||
//stringWidth := font.MeasureString(face, highScoreStr).Ceil()
|
//stringWidth := font.MeasureString(face, highScoreStr).Ceil()
|
||||||
@@ -38,8 +38,17 @@ func (sm *ScoreManager) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
//draw energy at the top
|
//draw energy at the top
|
||||||
energyStr := fmt.Sprintf("Energy: %v", geom.CurrentEnergy)
|
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()
|
stringWidth := font.MeasureString(face, energyStr).Ceil()
|
||||||
text.Draw(screen, energyStr, face, w/2-stringWidth/2, geom.ScoreOffset, color.White)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user