This commit is contained in:
Andrey Parhomenko 2023-12-25 23:41:12 +03:00
parent a3d7939d0e
commit b5ca8bef88
3 changed files with 19 additions and 2 deletions

View file

@ -52,5 +52,8 @@ func main() {
e.Add(tri) e.Add(tri)
fmt.Println(rect.GetLayer(), player.GetLayer()) fmt.Println(rect.GetLayer(), player.GetLayer())
e.Run() err = e.Run()
if err != nil {
panic(err)
}
} }

View file

@ -31,6 +31,10 @@ func NewPlayer() *Player {
return ret return ret
} }
func (p *Player) Start(c *Context) {
fmt.Println("library:", c.GraphicsLibrary())
}
// Custom drawing function. // Custom drawing function.
func (p *Player) Draw(c *Context) { func (p *Player) Draw(c *Context) {
p.Sprite.Draw(c) p.Sprite.Draw(c)

View file

@ -10,6 +10,9 @@ import (
"sync" "sync"
) )
type GraphicsLibrary = ebiten.GraphicsLibrary
type RunOptions = ebiten.RunGameOptions
// The type represents order of drawing. // The type represents order of drawing.
// Higher values are drawn later. // Higher values are drawn later.
type Layer float64 type Layer float64
@ -20,6 +23,8 @@ func (l Layer) GetLayer() Layer {
// Window configuration type. // Window configuration type.
type WindowConfig struct { type WindowConfig struct {
DebugInfo ebiten.DebugInfo
Options *RunOptions
// The title of the window. // The title of the window.
Title string Title string
@ -68,6 +73,10 @@ func (e *Engine) Keys() []Key {
return e.keys return e.keys
} }
func (e *Engine) GraphicsLibrary() GraphicsLibrary {
return e.wcfg.DebugInfo.GraphicsLibrary
}
// Returns currently pressed buttons. // Returns currently pressed buttons.
func (e *Engine) MouseButtons() []MouseButton { func (e *Engine) MouseButtons() []MouseButton {
ret := make([]MouseButton, len(e.buttons)) ret := make([]MouseButton, len(e.buttons))
@ -351,6 +360,7 @@ func (e *Engine) DT() Float {
} }
func (e *Engine) Run() error { func (e *Engine) Run() error {
ebiten.ReadDebugInfo(&e.wcfg.DebugInfo)
ebiten.SetWindowTitle(e.wcfg.Title) ebiten.SetWindowTitle(e.wcfg.Title)
ebiten.SetWindowSize(e.wcfg.Width, e.wcfg.Height) ebiten.SetWindowSize(e.wcfg.Width, e.wcfg.Height)
ebiten.SetWindowSizeLimits(1, 1, e.wcfg.Width, e.wcfg.Height) ebiten.SetWindowSizeLimits(1, 1, e.wcfg.Width, e.wcfg.Height)
@ -359,6 +369,6 @@ func (e *Engine) Run() error {
e.lastTime = time.Now() e.lastTime = time.Now()
//fmt.Println(e.Objects) //fmt.Println(e.Objects)
return ebiten.RunGame((*engine)(e)) return ebiten.RunGameWithOptions((*engine)(e), e.wcfg.Options)
} }