mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples: Add comment to explain about files
This commit is contained in:
parent
e7925a12bd
commit
93b2fab95b
@ -65,6 +65,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -52,6 +52,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -68,6 +68,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -71,6 +71,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -60,13 +60,23 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Specifying filter on NewImage(FromImage) is just for backward compatibility.
|
// Decode image from a byte slice instead of a file so that
|
||||||
// Now specifying filter at DrawImageOptions is recommended.
|
// this example works in any working directory.
|
||||||
// Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions.
|
// 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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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)
|
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
||||||
|
|
||||||
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Filter (Ebiten Demo)"); err != nil {
|
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Filter (Ebiten Demo)"); err != nil {
|
||||||
|
@ -84,6 +84,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -127,6 +127,15 @@ Inverted: %s [I]`, hue, saturation, value, msgInverted)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -57,6 +57,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -38,6 +38,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Tile_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -45,6 +45,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -39,6 +39,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -66,6 +66,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -61,6 +61,15 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -93,6 +93,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -95,6 +95,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -43,6 +43,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Tiles_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -45,6 +45,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.UI_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -154,6 +154,15 @@ FPS: %0.2f`, x, y, ebiten.CurrentFPS())
|
|||||||
func main() {
|
func main() {
|
||||||
fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor())
|
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))
|
img, _, err := image.Decode(bytes.NewReader(images.Gophers_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user