examples: Add comment to explain about files

This commit is contained in:
Hajime Hoshi
2018-03-16 12:05:53 +09:00
parent e7925a12bd
commit 93b2fab95b
18 changed files with 166 additions and 3 deletions

View File

@@ -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)