examples/platformer: Use embedded resources (#552)

This commit is contained in:
Hajime Hoshi 2018-03-15 00:21:16 +09:00
parent d5d577c733
commit 908ff43d2e

View File

@ -17,11 +17,14 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"image"
_ "image/png" _ "image/png"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
rplatformer "github.com/hajimehoshi/ebiten/examples/resources/images/platformer"
) )
const ( const (
@ -40,23 +43,29 @@ var (
func init() { func init() {
// Preload images // Preload images
var err error img, _, err := image.Decode(bytes.NewReader(rplatformer.Right_png))
rightSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/right.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
leftSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/left.png", ebiten.FilterDefault) rightSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
img, _, err = image.Decode(bytes.NewReader(rplatformer.Left_png))
if err != nil { if err != nil {
panic(err) panic(err)
} }
idleSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/mainchar.png", ebiten.FilterDefault) leftSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
img, _, err = image.Decode(bytes.NewReader(rplatformer.MainChar_png))
if err != nil { if err != nil {
panic(err) panic(err)
} }
backgroundImage, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/background.png", ebiten.FilterDefault) idleSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
img, _, err = image.Decode(bytes.NewReader(rplatformer.Background_png))
if err != nil { if err != nil {
panic(err) panic(err)
} }
backgroundImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
} }
var ( var (