Perf
This commit is contained in:
@@ -14,8 +14,15 @@ import (
|
|||||||
var (
|
var (
|
||||||
basicFace = text.NewGoXFace(basicfont.Face7x13)
|
basicFace = text.NewGoXFace(basicfont.Face7x13)
|
||||||
basicFaceAscent = basicFace.Metrics().HAscent
|
basicFaceAscent = basicFace.Metrics().HAscent
|
||||||
|
rectPixel = newRectPixel()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func newRectPixel() *ebiten.Image {
|
||||||
|
img := ebiten.NewImage(1, 1)
|
||||||
|
img.Fill(color.White)
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
func drawHUDText(screen *ebiten.Image, txt string, clr color.Color, x, y int) {
|
func drawHUDText(screen *ebiten.Image, txt string, clr color.Color, x, y int) {
|
||||||
if clr == nil {
|
if clr == nil {
|
||||||
clr = color.White
|
clr = color.White
|
||||||
@@ -132,16 +139,16 @@ func drawRect(screen *ebiten.Image, x, y, width, height int, clr color.Color) {
|
|||||||
if width <= 0 || height <= 0 {
|
if width <= 0 || height <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if clr == nil {
|
||||||
// Create a small 1x1 pixel image and scale it
|
clr = color.White
|
||||||
img := ebiten.NewImage(1, 1)
|
}
|
||||||
img.Fill(clr)
|
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Scale(float64(width), float64(height))
|
op.GeoM.Scale(float64(width), float64(height))
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
|
op.ColorScale.ScaleWithColor(clr)
|
||||||
|
|
||||||
screen.DrawImage(img, op)
|
screen.DrawImage(rectPixel, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty padding block.
|
// Empty padding block.
|
||||||
|
|||||||
@@ -13,8 +13,26 @@ import (
|
|||||||
var (
|
var (
|
||||||
basicFace = text.NewGoXFace(basicfont.Face7x13)
|
basicFace = text.NewGoXFace(basicfont.Face7x13)
|
||||||
basicFaceAscent = basicFace.Metrics().HAscent
|
basicFaceAscent = basicFace.Metrics().HAscent
|
||||||
|
overlayImage *ebiten.Image
|
||||||
|
overlaySize struct {
|
||||||
|
width int
|
||||||
|
height int
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getOverlayImage(width, height int) *ebiten.Image {
|
||||||
|
if width <= 0 || height <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if overlayImage == nil || overlaySize.width != width || overlaySize.height != height {
|
||||||
|
overlayImage = ebiten.NewImage(width, height)
|
||||||
|
overlayImage.Fill(color.RGBA{R: 0, G: 0, B: 0, A: 180})
|
||||||
|
overlaySize.width = width
|
||||||
|
overlaySize.height = height
|
||||||
|
}
|
||||||
|
return overlayImage
|
||||||
|
}
|
||||||
|
|
||||||
type MenuOption int
|
type MenuOption int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -69,9 +87,9 @@ func (m *PauseMenu) Update() *MenuOption {
|
|||||||
|
|
||||||
func (m *PauseMenu) Draw(screen *ebiten.Image, screenWidth, screenHeight int) {
|
func (m *PauseMenu) Draw(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||||
// Draw semi-transparent overlay
|
// Draw semi-transparent overlay
|
||||||
overlay := ebiten.NewImage(screenWidth, screenHeight)
|
if overlay := getOverlayImage(screenWidth, screenHeight); overlay != nil {
|
||||||
overlay.Fill(color.RGBA{R: 0, G: 0, B: 0, A: 180})
|
|
||||||
screen.DrawImage(overlay, nil)
|
screen.DrawImage(overlay, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Menu dimensions
|
// Menu dimensions
|
||||||
menuWidth := 400
|
menuWidth := 400
|
||||||
|
|||||||
Reference in New Issue
Block a user