diff --git a/ebitenutil/loadimage.go b/ebitenutil/loadimage.go index 6bc8e91e9..4a9408377 100644 --- a/ebitenutil/loadimage.go +++ b/ebitenutil/loadimage.go @@ -23,6 +23,9 @@ import ( ) // NewImageFromFile loads the file path and returns ebiten.Image and image.Image. +// +// The current directory for path depends on your environment. This will vary on your desktop or web browser. +// It'll be safer to embed your resource, e.g., with github.com/jteeuwen/go-bindata instead of using this function. func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.Image, error) { file, err := os.Open(path) if err != nil { diff --git a/example/internal/font.go b/example/internal/font.go index 3951552d6..61e7f48e4 100644 --- a/example/internal/font.go +++ b/example/internal/font.go @@ -42,8 +42,15 @@ func (f *Font) TextWidth(str string) int { } func init() { - _, path, _, _ := runtime.Caller(0) - arcadeFontPath := filepath.Join(filepath.Dir(path), "..", "images", "arcadefont.png") + dir := "" + if runtime.GOARCH != "js" { + // Get the path of this file (font.go). + _, path, _, _ := runtime.Caller(0) + path = filepath.Dir(path) + dir = filepath.Join(path, "..") + } + arcadeFontPath := filepath.Join(dir, "images", "arcadefont.png") + arcadeFontImage, _, err := ebitenutil.NewImageFromFile(arcadeFontPath, ebiten.FilterNearest) if err != nil { panic(err)