mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
example: Bug fix: the path from runtime.Caller is not useful on JavaScript (#99)
This commit is contained in:
parent
d12477fb2a
commit
f8c0fff6a7
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user