Use files in examples (#243)
Before Width: | Height: | Size: 1008 B After Width: | Height: | Size: 1008 B |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@ -20,7 +20,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -50,7 +50,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ebitenImage, _, err = common.AssetImage("ebiten.png", ebiten.FilterNearest)
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -223,7 +223,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -78,7 +78,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ebitenImage, _, err = common.AssetImage("ebiten.png", ebiten.FilterNearest)
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
@ -75,7 +76,7 @@ func init() {
|
||||
}
|
||||
imageEmpty.Fill(color.White)
|
||||
// Background
|
||||
imageGameBG, _, err = common.AssetImage("gophers.jpg", ebiten.FilterLinear)
|
||||
imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common/internal/assets"
|
||||
)
|
||||
|
||||
func AssetImage(path string, filter ebiten.Filter) (*ebiten.Image, image.Image, error) {
|
||||
b, err := assets.Asset("images/" + path)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
img, _, err := image.Decode(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
eimg, err := ebiten.NewImageFromImage(img, filter)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return eimg, img, nil
|
||||
}
|
@ -19,9 +19,12 @@ import (
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -43,7 +46,15 @@ func (f *Font) TextWidth(str string) int {
|
||||
}
|
||||
|
||||
func init() {
|
||||
arcadeFontImage, img, err := AssetImage("arcadefont.png", ebiten.FilterNearest)
|
||||
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, "_resources", "images", "arcadefont.png")
|
||||
arcadeFontImage, img, err := ebitenutil.NewImageFromFile(arcadeFontPath, ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package assets
|
||||
|
||||
// Unfortunately, go-bindata doesn't have an option for a whitelist.
|
||||
// Use -ignore as a blacklist instead.
|
||||
|
||||
//go:generate go-bindata -nocompress -pkg=assets -ignore=\.md$ images
|
||||
//go:generate gofmt -s -w .
|
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -95,7 +94,7 @@ Value: %0.2f [Z][X]`, hue, saturation, value)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -47,7 +47,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -108,11 +108,11 @@ func min(a, b int) int {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fiveyearsImage, _, err = common.AssetImage("fiveyears.jpg", ebiten.FilterNearest)
|
||||
fiveyearsImage, _, err = ebitenutil.NewImageFromFile("_resources/images/fiveyears.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -46,7 +46,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -66,7 +66,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -48,7 +48,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -139,7 +138,7 @@ Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Le
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ebitenImage, _, err = common.AssetImage("ebiten.png", ebiten.FilterNearest)
|
||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -104,7 +104,7 @@ FPS: %0.2f`, x, y, ebiten.CurrentFPS())
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
|
||||
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|