examples: Update comments

This commit is contained in:
Hajime Hoshi 2021-09-20 15:16:09 +09:00
parent c279d0c1cf
commit 537bdb29f8
32 changed files with 128 additions and 288 deletions

View File

@ -70,15 +70,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -36,15 +36,10 @@ const (
var ebitenImage *ebiten.Image var ebitenImage *ebiten.Image
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -46,15 +46,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -79,15 +79,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -65,15 +65,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Runner_png)) img, _, err := image.Decode(bytes.NewReader(images.Runner_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -122,15 +122,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -70,15 +70,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.FiveYears_jpg)) img, _, err := image.Decode(bytes.NewReader(images.FiveYears_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -53,15 +53,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Tiles_png)) img, _, err := image.Decode(bytes.NewReader(images.Tiles_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -73,15 +73,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -89,15 +89,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -192,15 +192,10 @@ type Game struct {
var ebitenImage *ebiten.Image var ebitenImage *ebiten.Image
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -66,15 +66,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -91,15 +91,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -43,15 +43,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -139,15 +139,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -65,15 +65,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -39,15 +39,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Tile_png)) img, _, err := image.Decode(bytes.NewReader(images.Tile_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -43,15 +43,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img1, _, err := image.Decode(bytes.NewReader(rmascot.Out01_png)) img1, _, err := image.Decode(bytes.NewReader(rmascot.Out01_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -42,15 +42,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -98,15 +98,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -39,15 +39,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -46,15 +46,10 @@ const (
var smokeImage *ebiten.Image var smokeImage *ebiten.Image
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Smoke_png)) img, _, err := image.Decode(bytes.NewReader(images.Smoke_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -70,15 +70,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -47,15 +47,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Tile_png)) img, _, err := image.Decode(bytes.NewReader(images.Tile_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -70,15 +70,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -42,15 +42,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(resources.Gopher_png)) img, _, err := image.Decode(bytes.NewReader(resources.Gopher_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -42,15 +42,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -44,15 +44,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png)) img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -44,15 +44,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Tiles_png)) img, _, err := image.Decode(bytes.NewReader(images.Tiles_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -229,15 +229,10 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -46,15 +46,10 @@ var (
) )
func init() { func init() {
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.UI_png)) img, _, err := image.Decode(bytes.NewReader(images.UI_png))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -377,15 +377,10 @@ func main() {
w, h := ebiten.ScreenSizeInFullscreen() w, h := ebiten.ScreenSizeInFullscreen()
fmt.Printf("Screen size in fullscreen: %d, %d\n", w, h) fmt.Printf("Screen size in fullscreen: %d, %d\n", w, h)
// Decode image from a byte slice instead of a file so that // Decode an image from a byte slice.
// this example works in any working directory. // Now this image file's byte slice is generated with //go:generated for Go 1.15 or older.
// If you want to use a file, there are some options: // If you use Go 1.16 or newer, it is strongly recommended to use //go:embed to embed the image file.
// 1) Use os.Open and pass the file to the image decoder. // See https://pkg.go.dev/embed for more details.
// This is a very regular way, but doesn't work on browsers.
// 2) Use ebitenutil.OpenFile and pass the file to the image decoder.
// This works even on browsers.
// 3) Use ebitenutil.NewImageFromFile to create an ebiten.Image directly from a file.
// This also works on browsers.
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg)) img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)