added mouse cursor
This commit is contained in:
parent
b330bfa184
commit
5fbb9b3545
Binary file not shown.
After Width: | Height: | Size: 240 B |
20
run.go
20
run.go
|
@ -1,6 +1,7 @@
|
||||||
package bloob
|
package bloob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,8 +22,14 @@ type Settings struct {
|
||||||
|
|
||||||
type Bloob struct {
|
type Bloob struct {
|
||||||
MousePos Vec2i
|
MousePos Vec2i
|
||||||
|
Cursor *Image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DefaultCursor *Image
|
||||||
|
|
||||||
|
//go:embed "cursor.png"
|
||||||
|
var defaultCursorBytes []byte
|
||||||
|
|
||||||
func Run(game Runnable) {
|
func Run(game Runnable) {
|
||||||
_ = sdl.Init(sdl.INIT_EVERYTHING)
|
_ = sdl.Init(sdl.INIT_EVERYTHING)
|
||||||
defer sdl.Quit()
|
defer sdl.Quit()
|
||||||
|
@ -34,7 +41,13 @@ func Run(game Runnable) {
|
||||||
Title: "Blooblib",
|
Title: "Blooblib",
|
||||||
}
|
}
|
||||||
|
|
||||||
bloob := Bloob{}
|
if DefaultCursor == nil {
|
||||||
|
DefaultCursor = LoadImageBytes(defaultCursorBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
bloob := Bloob{
|
||||||
|
Cursor: DefaultCursor,
|
||||||
|
}
|
||||||
|
|
||||||
game.Init(&settings)
|
game.Init(&settings)
|
||||||
|
|
||||||
|
@ -51,6 +64,8 @@ func Run(game Runnable) {
|
||||||
screen := NewImage(settings.WindowSize)
|
screen := NewImage(settings.WindowSize)
|
||||||
screen.Alpha = false
|
screen.Alpha = false
|
||||||
|
|
||||||
|
sdl.ShowCursor(sdl.DISABLE)
|
||||||
|
|
||||||
_ = window.UpdateSurface()
|
_ = window.UpdateSurface()
|
||||||
|
|
||||||
lastSecond := time.Now()
|
lastSecond := time.Now()
|
||||||
|
@ -85,6 +100,9 @@ func Run(game Runnable) {
|
||||||
if delta2 >= frameDuration {
|
if delta2 >= frameDuration {
|
||||||
game.Update(&bloob)
|
game.Update(&bloob)
|
||||||
game.Render(screen)
|
game.Render(screen)
|
||||||
|
if bloob.Cursor != nil {
|
||||||
|
screen.Draw(bloob.Cursor, bloob.MousePos)
|
||||||
|
}
|
||||||
windowImage.DrawUpscale(screen)
|
windowImage.DrawUpscale(screen)
|
||||||
framesSinceLastSecond += 1
|
framesSinceLastSecond += 1
|
||||||
lastFrame = lastFrame.Add(frameDuration)
|
lastFrame = lastFrame.Add(frameDuration)
|
||||||
|
|
Loading…
Reference in New Issue