diff --git a/examples/additive/main.go b/examples/additive/main.go index 9696c5421..c58761536 100644 --- a/examples/additive/main.go +++ b/examples/additive/main.go @@ -65,6 +65,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/airship/main.go b/examples/airship/main.go index 97e5cbff9..bf1dc2b73 100644 --- a/examples/airship/main.go +++ b/examples/airship/main.go @@ -52,6 +52,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/alphablending/main.go b/examples/alphablending/main.go index 461358540..255318165 100644 --- a/examples/alphablending/main.go +++ b/examples/alphablending/main.go @@ -68,6 +68,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/contextlost/main.go b/examples/contextlost/main.go index 5d660cbb7..44702351c 100644 --- a/examples/contextlost/main.go +++ b/examples/contextlost/main.go @@ -71,6 +71,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/filter/main.go b/examples/filter/main.go index 678ce44de..cbe20d55a 100644 --- a/examples/filter/main.go +++ b/examples/filter/main.go @@ -60,13 +60,23 @@ func update(screen *ebiten.Image) error { } func main() { - // Specifying filter on NewImage(FromImage) is just for backward compatibility. - // Now specifying filter at DrawImageOptions is recommended. - // Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions. + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) } + + // Specifying filter on NewImage[FromImage] is just for backward compatibility. + // Now specifying filter at DrawImageOptions is recommended. + // Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions. ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault) if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Filter (Ebiten Demo)"); err != nil { diff --git a/examples/flood/main.go b/examples/flood/main.go index 6f19a201e..37715a934 100644 --- a/examples/flood/main.go +++ b/examples/flood/main.go @@ -84,6 +84,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/hsv/main.go b/examples/hsv/main.go index c441b6944..5ed4dd1ee 100644 --- a/examples/hsv/main.go +++ b/examples/hsv/main.go @@ -127,6 +127,15 @@ Inverted: %s [I]`, hue, saturation, value, msgInverted) } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/hue/main.go b/examples/hue/main.go index dc479638d..60def6ebc 100644 --- a/examples/hue/main.go +++ b/examples/hue/main.go @@ -57,6 +57,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/infinitescroll/main.go b/examples/infinitescroll/main.go index 2790954f9..81e3aaee9 100644 --- a/examples/infinitescroll/main.go +++ b/examples/infinitescroll/main.go @@ -38,6 +38,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/masking/main.go b/examples/masking/main.go index 71f00a404..fb3295dd7 100644 --- a/examples/masking/main.go +++ b/examples/masking/main.go @@ -45,6 +45,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/mosaic/main.go b/examples/mosaic/main.go index 92ce25f6a..02071e76d 100644 --- a/examples/mosaic/main.go +++ b/examples/mosaic/main.go @@ -39,6 +39,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/perspective/main.go b/examples/perspective/main.go index e3506a151..c83043102 100644 --- a/examples/perspective/main.go +++ b/examples/perspective/main.go @@ -66,6 +66,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/rotate/main.go b/examples/rotate/main.go index 15922c68f..b8eaf57a0 100644 --- a/examples/rotate/main.go +++ b/examples/rotate/main.go @@ -61,6 +61,15 @@ func update(screen *ebiten.Image) error { } func main() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/sprites/main.go b/examples/sprites/main.go index de8bff941..d97b5d0e7 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -93,6 +93,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/spriteshd/main.go b/examples/spriteshd/main.go index d9180afe7..237950a92 100644 --- a/examples/spriteshd/main.go +++ b/examples/spriteshd/main.go @@ -95,6 +95,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/tiles/main.go b/examples/tiles/main.go index 94ce660e2..fe48483c1 100644 --- a/examples/tiles/main.go +++ b/examples/tiles/main.go @@ -43,6 +43,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/ui/main.go b/examples/ui/main.go index 497cb667f..aa868f5da 100644 --- a/examples/ui/main.go +++ b/examples/ui/main.go @@ -45,6 +45,15 @@ var ( ) func init() { + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err) diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 165ca321d..2cb82ce6c 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -154,6 +154,15 @@ FPS: %0.2f`, x, y, ebiten.CurrentFPS()) func main() { fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor()) + // Decode image from a byte slice instead of a file so that + // this example works in any working directory. + // If you want to use a file, there are some options: + // 1) Use os.Open and pass the file to the image decoder. + // 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)) if err != nil { log.Fatal(err)