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

View File

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

View File

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