examples/blocks: Use embedded resources (#552)

This commit is contained in:
Hajime Hoshi 2018-03-14 12:19:05 +09:00
parent 08beed4306
commit d5d577c733
3 changed files with 15 additions and 8 deletions

View File

@ -15,6 +15,8 @@
package blocks package blocks
import ( import (
"bytes"
"image"
"image/color" "image/color"
_ "image/jpeg" _ "image/jpeg"
_ "image/png" _ "image/png"
@ -24,6 +26,7 @@ import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/examples/resources/images"
"github.com/hajimehoshi/ebiten/inpututil" "github.com/hajimehoshi/ebiten/inpututil"
) )
@ -69,11 +72,11 @@ func linesTextBoxPosition() (x, y int) {
func init() { func init() {
// Background // Background
var err error img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
imageGameBG, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
// Windows // Windows
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault) imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)

View File

@ -15,21 +15,23 @@
package blocks package blocks
import ( import (
"bytes"
"image" "image"
_ "image/png" _ "image/png"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" rblocks "github.com/hajimehoshi/ebiten/examples/resources/images/blocks"
) )
var imageBlocks *ebiten.Image var imageBlocks *ebiten.Image
func init() { func init() {
var err error img, _, err := image.Decode(bytes.NewReader(rblocks.Blocks_png))
imageBlocks, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/blocks.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
imageBlocks, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
} }
type Angle int type Angle int

View File

@ -15,22 +15,24 @@
package blocks package blocks
import ( import (
"bytes"
"image"
"image/color" "image/color"
_ "image/png" _ "image/png"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" rblocks "github.com/hajimehoshi/ebiten/examples/resources/images/blocks"
"github.com/hajimehoshi/ebiten/inpututil" "github.com/hajimehoshi/ebiten/inpututil"
) )
var imageBackground *ebiten.Image var imageBackground *ebiten.Image
func init() { func init() {
var err error img, _, err := image.Decode(bytes.NewReader(rblocks.Background_png))
imageBackground, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/background.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
imageBackground, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
} }
type TitleScene struct { type TitleScene struct {