diff --git a/_docs/examplecontent.tmpl.html b/_docs/examplecontent.tmpl.html
index 3f53e3e05..7bb94e105 100644
--- a/_docs/examplecontent.tmpl.html
+++ b/_docs/examplecontent.tmpl.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = '{{.Example.Name}}.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/_resources/images/images/keyboard/keyboard.png b/docs/examples/_resources/images/images/keyboard/keyboard.png
index 35a21dcbf..6dfd5782c 100644
Binary files a/docs/examples/_resources/images/images/keyboard/keyboard.png and b/docs/examples/_resources/images/images/keyboard/keyboard.png differ
diff --git a/docs/examples/_resources/images/keyboard/keyboard.png b/docs/examples/_resources/images/keyboard/keyboard.png
index 35a21dcbf..6dfd5782c 100644
Binary files a/docs/examples/_resources/images/keyboard/keyboard.png and b/docs/examples/_resources/images/keyboard/keyboard.png differ
diff --git a/docs/examples/alphablending.content.html b/docs/examples/alphablending.content.html
index 2ffe0e807..b227ac95c 100644
--- a/docs/examples/alphablending.content.html
+++ b/docs/examples/alphablending.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'alphablending.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/alphablending.html b/docs/examples/alphablending.html
index 4eb54f659..22c4fa6ed 100644
--- a/docs/examples/alphablending.html
+++ b/docs/examples/alphablending.html
@@ -48,26 +48,6 @@ var (
ebitenImage *ebiten.Image
)
-type imageParts struct {
- diff float64
-}
-
-func (p *imageParts) Src(i int) (int, int, int, int) {
- w, h := ebitenImage.Size()
- return 0, 0, w, h
-}
-
-func (p *imageParts) Dst(i int) (int, int, int, int) {
- x := int(float64(i%10)*p.diff + 15)
- y := int(float64(i/10)*p.diff + 20)
- w, h := ebitenImage.Size()
- return x, y, x + w, y + h
-}
-
-func (p *imageParts) Len() int {
- return 10 * 10
-}
-
func update(screen *ebiten.Image) error {
count++
count %= ebiten.FPS * 10
@@ -84,10 +64,13 @@ func update(screen *ebiten.Image) error {
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
- op.ImageParts = &imageParts{
- diff: diff,
+ for i := 0; i < 10*10; i++ {
+ op.GeoM.Reset()
+ x := float64(i%10)*diff + 15
+ y := float64(i/10)*diff + 20
+ op.GeoM.Translate(x, y)
+ screen.DrawImage(ebitenImage, op)
}
- screen.DrawImage(ebitenImage, op)
return nil
}
diff --git a/docs/examples/audio.content.html b/docs/examples/audio.content.html
index 93c863c20..ed3b1f4b6 100644
--- a/docs/examples/audio.content.html
+++ b/docs/examples/audio.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'audio.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/blocks.content.html b/docs/examples/blocks.content.html
index 824ef2c0b..8f9ac8fe7 100644
--- a/docs/examples/blocks.content.html
+++ b/docs/examples/blocks.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'blocks.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/font.content.html b/docs/examples/font.content.html
index f67c3b128..1d14f7c5d 100644
--- a/docs/examples/font.content.html
+++ b/docs/examples/font.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'font.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/gamepad.content.html b/docs/examples/gamepad.content.html
index 6303c5152..08bbfaa96 100644
--- a/docs/examples/gamepad.content.html
+++ b/docs/examples/gamepad.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'gamepad.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/hsv.content.html b/docs/examples/hsv.content.html
index feb9ec368..49acf6650 100644
--- a/docs/examples/hsv.content.html
+++ b/docs/examples/hsv.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'hsv.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/hue.content.html b/docs/examples/hue.content.html
index a184f3ade..9329f3086 100644
--- a/docs/examples/hue.content.html
+++ b/docs/examples/hue.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'hue.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/infinitescroll.content.html b/docs/examples/infinitescroll.content.html
index 9811d45fa..008eadf62 100644
--- a/docs/examples/infinitescroll.content.html
+++ b/docs/examples/infinitescroll.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'infinitescroll.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/keyboard.content.html b/docs/examples/keyboard.content.html
index 753f22ec7..d9719b45e 100644
--- a/docs/examples/keyboard.content.html
+++ b/docs/examples/keyboard.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'keyboard.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/keyboard.html b/docs/examples/keyboard.html
index 009979b99..bd8964dd0 100644
--- a/docs/examples/keyboard.html
+++ b/docs/examples/keyboard.html
@@ -54,14 +54,22 @@ func init() {
}
var keyNames = map[ebiten.Key]string{
- ebiten.KeyBackspace: "BS",
- ebiten.KeyComma: ",",
- ebiten.KeyDelete: "Del",
- ebiten.KeyEnter: "Enter",
- ebiten.KeyEscape: "Esc",
- ebiten.KeyPeriod: ".",
- ebiten.KeySpace: "Space",
- ebiten.KeyTab: "Tab",
+ ebiten.KeyBackspace: "BS",
+ ebiten.KeyComma: ",",
+ ebiten.KeyEnter: "Enter",
+ ebiten.KeyEscape: "Esc",
+ ebiten.KeyPeriod: ".",
+ ebiten.KeySpace: "Space",
+ ebiten.KeyTab: "Tab",
+ ebiten.KeyMinus: "-",
+ ebiten.KeyEqual: "=",
+ ebiten.KeyBackslash: "\\",
+ ebiten.KeyGraveAccent: "`",
+ ebiten.KeyLeftBracket: "[",
+ ebiten.KeyRightBracket: "]",
+ ebiten.KeySemicolon: ";",
+ ebiten.KeyApostrophe: "'",
+ ebiten.KeySlash: "/",
// Arrows
ebiten.KeyDown: "Down",
@@ -75,26 +83,10 @@ var keyNames = map[ebiten.Key]string{
ebiten.KeyAlt: "Alt",
}
-type pressedKeysParts []string
-
-func (p pressedKeysParts) Len() int {
- return len(p)
-}
-
-func (p pressedKeysParts) Dst(i int) (x0, y0, x1, y1 int) {
- k := p[i]
- r, ok := keyboard.KeyRect(k)
- if !ok {
- return 0, 0, 0, 0
- }
- return r.Min.X, r.Min.Y, r.Max.X, r.Max.Y
-}
-
-func (p pressedKeysParts) Src(i int) (x0, y0, x1, y1 int) {
- return p.Dst(i)
-}
-
func update(screen *ebiten.Image) error {
+ if ebiten.IsRunningSlowly() {
+ return nil
+ }
const offsetX, offsetY = 24, 40
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(offsetX, offsetY)
@@ -123,11 +115,18 @@ func update(screen *ebiten.Image) error {
}
}
- op = &ebiten.DrawImageOptions{
- ImageParts: pressedKeysParts(pressed),
+ op = &ebiten.DrawImageOptions{}
+ for _, p := range pressed {
+ op.GeoM.Reset()
+ r, ok := keyboard.KeyRect(p)
+ if !ok {
+ continue
+ }
+ op.GeoM.Translate(float64(r.Min.X), float64(r.Min.Y))
+ op.GeoM.Translate(offsetX, offsetY)
+ op.SourceRect = &r
+ screen.DrawImage(keyboardImage, op)
}
- op.GeoM.Translate(offsetX, offsetY)
- screen.DrawImage(keyboardImage, op)
return nil
}
diff --git a/docs/examples/life.content.html b/docs/examples/life.content.html
index 3ca1a049c..903f5b612 100644
--- a/docs/examples/life.content.html
+++ b/docs/examples/life.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'life.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/masking.content.html b/docs/examples/masking.content.html
index 8d0c409fd..85e592e69 100644
--- a/docs/examples/masking.content.html
+++ b/docs/examples/masking.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'masking.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/mosaic.content.html b/docs/examples/mosaic.content.html
index 8849d1f2a..c1e427f9d 100644
--- a/docs/examples/mosaic.content.html
+++ b/docs/examples/mosaic.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'mosaic.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/noise.content.html b/docs/examples/noise.content.html
index 0056ceac5..af439b853 100644
--- a/docs/examples/noise.content.html
+++ b/docs/examples/noise.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'noise.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/paint.content.html b/docs/examples/paint.content.html
index 43a71feca..4865c9e22 100644
--- a/docs/examples/paint.content.html
+++ b/docs/examples/paint.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'paint.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/perspective.content.html b/docs/examples/perspective.content.html
index 418686a11..1ada5ea0a 100644
--- a/docs/examples/perspective.content.html
+++ b/docs/examples/perspective.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'perspective.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/perspective.html b/docs/examples/perspective.html
index 72ae0f82b..9ab9981d7 100644
--- a/docs/examples/perspective.html
+++ b/docs/examples/perspective.html
@@ -30,6 +30,7 @@
package main
import (
+ "image"
_ "image/jpeg"
"log"
@@ -46,39 +47,25 @@ var (
gophersImage *ebiten.Image
)
-type parts struct {
- image *ebiten.Image
-}
-
-func (p parts) Len() int {
- _, h := p.image.Size()
- return h
-}
-
-func (p parts) Dst(i int) (x0, y0, x1, y1 int) {
- w, h := p.image.Size()
- width := w + i*3/4
- x := ((h - i) * 3 / 4) / 2
- return x, i, x + width, i + 1
-}
-
-func (p parts) Src(i int) (x0, y0, x1, y1 int) {
- w, _ := p.image.Size()
- return 0, i, w, i + 1
-}
-
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
- op := &ebiten.DrawImageOptions{
- ImageParts: &parts{gophersImage},
- }
+ op := &ebiten.DrawImageOptions{}
w, h := gophersImage.Size()
- maxWidth := float64(w) + float64(h)*0.75
- op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
- op.GeoM.Translate(screenWidth/2, screenHeight/2)
- screen.DrawImage(gophersImage, op)
+ for i := 0; i < h; i++ {
+ op.GeoM.Reset()
+ width := w + i*3/4
+ x := ((h - i) * 3 / 4) / 2
+ op.GeoM.Scale(float64(width)/float64(w), 1)
+ op.GeoM.Translate(float64(x), float64(i))
+ maxWidth := float64(w) + float64(h)*3/4
+ op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
+ op.GeoM.Translate(screenWidth/2, screenHeight/2)
+ r := image.Rect(0, i, w, i+1)
+ op.SourceRect = &r
+ screen.DrawImage(gophersImage, op)
+ }
return nil
}
diff --git a/docs/examples/piano.content.html b/docs/examples/piano.content.html
index c8d6c45d1..2845eccb2 100644
--- a/docs/examples/piano.content.html
+++ b/docs/examples/piano.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'piano.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/rotate.content.html b/docs/examples/rotate.content.html
index a1315feef..e5397fb53 100644
--- a/docs/examples/rotate.content.html
+++ b/docs/examples/rotate.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'rotate.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/sprites.content.html b/docs/examples/sprites.content.html
index 00bb6abaf..155de2fe8 100644
--- a/docs/examples/sprites.content.html
+++ b/docs/examples/sprites.content.html
@@ -16,7 +16,7 @@ window.addEventListener('load', function() {
var s = document.createElement('script');
var src = 'sprites.js';
if (isProduction()) {
- src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
+ src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
}
s.src = src;
s.onload = function() {
diff --git a/docs/examples/sprites.html b/docs/examples/sprites.html
index c962228e2..66ce742af 100644
--- a/docs/examples/sprites.html
+++ b/docs/examples/sprites.html
@@ -33,6 +33,7 @@ import (
"fmt"
_ "image/png"
"log"
+ "math"
"math/rand"
"github.com/hajimehoshi/ebiten"
@@ -42,12 +43,11 @@ import (
const (
screenWidth = 320
screenHeight = 240
+ maxAngle = 256
)
var (
- ebitenImage *ebiten.Image
- ebitenImageWidth = 0
- ebitenImageHeight = 0
+ ebitenImage *ebiten.Image
)
type Sprite struct {
@@ -57,6 +57,7 @@ type Sprite struct {
y int
vx int
vy int
+ angle int
}
func (s *Sprite) Update() {
@@ -76,6 +77,8 @@ func (s *Sprite) Update() {
s.y = 2*(screenHeight-s.imageHeight) - s.y
s.vy = -s.vy
}
+ s.angle++
+ s.angle %= maxAngle
}
type Sprites struct {
@@ -89,31 +92,15 @@ func (s *Sprites) Update() {
}
}
-func (s *Sprites) Len() int {
- return s.num
-}
-
-func (s *Sprites) Dst(i int) (x0, y0, x1, y1 int) {
- if s.num <= i {
- return 0, 0, 0, 0
- }
- ss := s.sprites[i]
- return ss.x, ss.y, ss.x + ebitenImageWidth, ss.y + ebitenImageHeight
-}
-
-func (s *Sprites) Src(i int) (x0, y0, x1, y1 int) {
- if s.num <= i {
- return 0, 0, 0, 0
- }
- return 0, 0, ebitenImageWidth, ebitenImageHeight
-}
-
const (
MinSprites = 0
MaxSprites = 50000
)
-var sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
+var (
+ sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
+ op = &ebiten.DrawImageOptions{}
+)
func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
@@ -133,29 +120,41 @@ func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
- op := &ebiten.DrawImageOptions{
- ImageParts: sprites,
+ w, h := ebitenImage.Size()
+ for i := 0; i < sprites.num; i++ {
+ s := sprites.sprites[i]
+ op.GeoM.Reset()
+ op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
+ op.GeoM.Rotate(2 * math.Pi * float64(s.angle) / maxAngle)
+ op.GeoM.Translate(float64(w)/2, float64(h)/2)
+ op.GeoM.Translate(float64(s.x), float64(s.y))
+ screen.DrawImage(ebitenImage, op)
}
- op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
- screen.DrawImage(ebitenImage, op)
msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d
-Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
- ebitenutil.DebugPrint(screen, msg)
+Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.num)
+ if err := ebitenutil.DebugPrint(screen, msg); err != nil {
+ return err
+ }
return nil
}
func main() {
var err error
- ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
+ img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
- ebitenImageWidth, ebitenImageHeight = ebitenImage.Size()
+ w, h := img.Size()
+ ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest)
+ op := &ebiten.DrawImageOptions{}
+ op.ColorM.Scale(1, 1, 1, 0.5)
+ ebitenImage.DrawImage(img, op)
for i := range sprites.sprites {
w, h := ebitenImage.Size()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
+ a := rand.Intn(maxAngle)
sprites.sprites[i] = &Sprite{
imageWidth: w,
imageHeight: h,
@@ -163,6 +162,7 @@ func main() {
y: y,
vx: vx,
vy: vy,
+ angle: a,
}
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil {