mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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.
|
// 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) {
|
func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.Image, error) {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,8 +42,15 @@ func (f *Font) TextWidth(str string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_, path, _, _ := runtime.Caller(0)
|
dir := ""
|
||||||
arcadeFontPath := filepath.Join(filepath.Dir(path), "..", "images", "arcadefont.png")
|
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)
|
arcadeFontImage, _, err := ebitenutil.NewImageFromFile(arcadeFontPath, ebiten.FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user