added mouse cursor

This commit is contained in:
Squishy Bloob 2024-03-23 09:12:55 +00:00
parent b330bfa184
commit 5fbb9b3545
2 changed files with 19 additions and 1 deletions

BIN
cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

20
run.go
View File

@ -1,6 +1,7 @@
package bloob
import (
_ "embed"
"fmt"
"github.com/veandco/go-sdl2/sdl"
"time"
@ -21,8 +22,14 @@ type Settings struct {
type Bloob struct {
MousePos Vec2i
Cursor *Image
}
var DefaultCursor *Image
//go:embed "cursor.png"
var defaultCursorBytes []byte
func Run(game Runnable) {
_ = sdl.Init(sdl.INIT_EVERYTHING)
defer sdl.Quit()
@ -34,7 +41,13 @@ func Run(game Runnable) {
Title: "Blooblib",
}
bloob := Bloob{}
if DefaultCursor == nil {
DefaultCursor = LoadImageBytes(defaultCursorBytes)
}
bloob := Bloob{
Cursor: DefaultCursor,
}
game.Init(&settings)
@ -51,6 +64,8 @@ func Run(game Runnable) {
screen := NewImage(settings.WindowSize)
screen.Alpha = false
sdl.ShowCursor(sdl.DISABLE)
_ = window.UpdateSurface()
lastSecond := time.Now()
@ -85,6 +100,9 @@ func Run(game Runnable) {
if delta2 >= frameDuration {
game.Update(&bloob)
game.Render(screen)
if bloob.Cursor != nil {
screen.Draw(bloob.Cursor, bloob.MousePos)
}
windowImage.DrawUpscale(screen)
framesSinceLastSecond += 1
lastFrame = lastFrame.Add(frameDuration)