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