mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
2eac4a3b88
commit
10080d83e6
@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
)
|
||||
@ -62,3 +63,7 @@ func OpenFile(path string) (ReadSeekCloser, error) {
|
||||
f := &file{bytes.NewReader(data)}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func JoinStringsIntoFilePath(elems ...string) string {
|
||||
return path.Join(elems...)
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package ebitenutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// OpenFile opens a file and returns a stream for its data.
|
||||
@ -30,3 +31,12 @@ import (
|
||||
func OpenFile(path string) (ReadSeekCloser, error) {
|
||||
return os.Open(path)
|
||||
}
|
||||
|
||||
// JoinFilePath joins any number of path elements into a single path,
|
||||
// adding a Separator if necessary.
|
||||
//
|
||||
// This is basically same as filepath.Join, but the behavior is different on JavaScript.
|
||||
// For browsers, path.Join is called instead of filepath.Join.
|
||||
func JoinStringsIntoFilePath(elems ...string) string {
|
||||
return filepath.Join(elems...)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ var (
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ func playerBarRect() (x, y, w, h int) {
|
||||
|
||||
func NewPlayer(audioContext *audio.Context) (*Player, error) {
|
||||
const bytesPerSample = 4 // TODO: This should be defined in audio package
|
||||
wavF, err := ebitenutil.OpenFile("_resources/audio/jab.wav")
|
||||
wavF, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "jab.wav"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mp3F, err := ebitenutil.OpenFile("_resources/audio/classic.mp3")
|
||||
mp3F, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "classic.mp3"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func linesTextBoxPosition() (x, y int) {
|
||||
func init() {
|
||||
// Background
|
||||
var err error
|
||||
imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear)
|
||||
imageGameBG, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterLinear)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var imageBlocks *ebiten.Image
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
imageBlocks, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/blocks.png", ebiten.FilterNearest)
|
||||
imageBlocks, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "blocks", "blocks.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ var imageBackground *ebiten.Image
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
imageBackground, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/background.png", ebiten.FilterNearest)
|
||||
imageBackground, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "blocks", "background.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ Inverted: %s [I]`, hue, saturation, value, msgInverted)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest)
|
||||
bgImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "tile.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ var keyboardImage *ebiten.Image
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterNearest)
|
||||
keyboardImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "keyboard", "keyboard.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -100,11 +100,11 @@ func min(a, b int) int {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fiveyearsImage, _, err = ebitenutil.NewImageFromFile("_resources/images/fiveyears.jpg", ebiten.FilterNearest)
|
||||
fiveyearsImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "fiveyears.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -81,19 +81,19 @@ func update(screen *ebiten.Image) error {
|
||||
func main() {
|
||||
// Preload images
|
||||
var err error
|
||||
rightSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/right.png", ebiten.FilterNearest)
|
||||
rightSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "right.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
leftSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/left.png", ebiten.FilterNearest)
|
||||
leftSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "left.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
idleSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/mainchar.png", ebiten.FilterNearest)
|
||||
idleSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "mainchar.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
backgroundImage, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/background.png", ebiten.FilterNearest)
|
||||
backgroundImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "background.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.nu
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
img, _, err := ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ var (
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
uiImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ui.png", ebiten.FilterNearest)
|
||||
uiImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ui.png"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func init() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := ebitenutil.OpenFile("_resources/audio/jab.wav")
|
||||
f, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "jab.wav"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ FPS: %0.2f`, x, y, ebiten.CurrentFPS())
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user