Eager load used sprites

This commit is contained in:
2020-03-21 10:59:07 +00:00
parent 7a8e9dbd97
commit 8b02f534f1
3 changed files with 35 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package assetstore
import (
"fmt"
"log"
"github.com/hajimehoshi/ebiten"
@@ -18,6 +19,7 @@ type Object struct {
type Sprite struct {
obj *Object
ID string
XOffset int
YOffset int
Width int
@@ -50,8 +52,8 @@ func (a *AssetStore) Object(name string) (*Object, error) {
sprites: make([]*Sprite, int(raw.NumSprites)),
raw: raw,
}
a.objs[name] = obj
a.objs[name] = obj
return obj, nil
}
@@ -75,6 +77,7 @@ func (o *Object) Sprite(idx int) (*Sprite, error) {
}
sprite := &Sprite{
ID: fmt.Sprintf("%v:%v", o.raw.Name, idx),
obj: o,
Width: int(raw.Width),
Height: int(raw.Width),