assets -> game, and no embed for native
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 605 B After Width: | Height: | Size: 605 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 472 KiB After Width: | Height: | Size: 472 KiB |
11
game/assets_js.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
//go:build js
|
||||
// +build js
|
||||
|
||||
package game
|
||||
|
||||
// TODO: make io/fs wrapper for ebitenutil.OpenFile ?
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed assets
|
||||
var Assets embed.FS
|
8
game/assets_notjs.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
//go:build !js
|
||||
// +build !js
|
||||
|
||||
package game
|
||||
|
||||
import "os"
|
||||
|
||||
var Assets = os.DirFS("game/")
|
12
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/png"
|
||||
|
@ -12,9 +11,6 @@ import (
|
|||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
//go:embed assets
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
ebiten.SetWindowResizable(true)
|
||||
ebiten.SetWindowSize(640, 480)
|
||||
|
@ -111,7 +107,7 @@ func main() {
|
|||
},
|
||||
}
|
||||
|
||||
game := &engine.Game{
|
||||
g := &engine.Game{
|
||||
ScreenHeight: 240,
|
||||
ScreenWidth: 320,
|
||||
Root: &engine.Scene{
|
||||
|
@ -131,12 +127,12 @@ func main() {
|
|||
},
|
||||
},
|
||||
}
|
||||
if err := game.Load(assets); err != nil {
|
||||
if err := g.Load(game.Assets); err != nil {
|
||||
log.Fatalf("Loading error: %v", err)
|
||||
}
|
||||
game.Prepare()
|
||||
g.Prepare()
|
||||
|
||||
if err := ebiten.RunGame(game); err != nil {
|
||||
if err := ebiten.RunGame(g); err != nil {
|
||||
log.Fatalf("Game error: %v", err)
|
||||
}
|
||||
}
|
||||
|
|