mirror of
https://github.com/Kugelschieber/go-game.git
synced 2026-01-18 06:40:28 +00:00
Added function to easily access loaded textures.
This commit is contained in:
1
ToDo.md
1
ToDo.md
@@ -4,3 +4,4 @@
|
|||||||
* more logging
|
* more logging
|
||||||
* limit FPS
|
* limit FPS
|
||||||
* fullscreen
|
* fullscreen
|
||||||
|
* simple access to default resources like GetTex()
|
||||||
|
|||||||
@@ -11,24 +11,25 @@ const (
|
|||||||
type Game struct{}
|
type Game struct{}
|
||||||
|
|
||||||
func (g *Game) Setup() {
|
func (g *Game) Setup() {
|
||||||
res, err := goga.LoadRes(gopher_path)
|
// load texture
|
||||||
|
_, err := goga.LoadRes(gopher_path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tex, ok := res.(*goga.Tex)
|
// create sprite
|
||||||
|
tex, err := goga.GetTex("gopher.png")
|
||||||
|
|
||||||
if !ok {
|
if err != nil {
|
||||||
panic("Resource is not a texture")
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite := goga.NewSprite(tex)
|
sprite := goga.NewSprite(tex)
|
||||||
goga.AddActor(sprite)
|
goga.AddActor(sprite)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update(delta float64) {
|
func (g *Game) Update(delta float64) {}
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
game := Game{}
|
game := Game{}
|
||||||
|
|||||||
23
res_util.go
Normal file
23
res_util.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package goga
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Finds and returns a Tex resource.
|
||||||
|
// If not found or when the resource is of wrong type, an error will be returned.
|
||||||
|
func GetTex(name string) (*Tex, error) {
|
||||||
|
res := GetResByName(name)
|
||||||
|
|
||||||
|
if res == nil {
|
||||||
|
return nil, errors.New("Resource not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
tex, ok := res.(*Tex)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("Resource was not of type *Tex")
|
||||||
|
}
|
||||||
|
|
||||||
|
return tex, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user