examples: Call IsRunningSlowly (#354)

This commit is contained in:
Hajime Hoshi 2017-05-16 10:35:58 +09:00
parent 9f53404655
commit a657cac229
20 changed files with 66 additions and 27 deletions

View File

@ -35,13 +35,13 @@ var (
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
w, _ := ebitenImage.Size() w, _ := ebitenImage.Size()
const ox = 10 const ox = 10
const oy = 10 const oy = 10
screen.Fill(color.NRGBA{0x00, 0x40, 0x80, 0xff})
if err := screen.Fill(color.NRGBA{0x00, 0x40, 0x80, 0xff}); err != nil {
return err
}
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(ox, oy) op.GeoM.Translate(ox, oy)
screen.DrawImage(ebitenImage, op) screen.DrawImage(ebitenImage, op)

View File

@ -194,11 +194,12 @@ func update(screen *ebiten.Image) error {
if !rotated { if !rotated {
thePlayer.Stabilize() thePlayer.Stabilize()
} }
if ebiten.IsRunningSlowly() {
return nil
}
screen.Fill(skyColor) screen.Fill(skyColor)
updateGroundImage(groundImage) updateGroundImage(groundImage)
drawGroundImage(screen, groundImage) drawGroundImage(screen, groundImage)
tutrial := "Space: Move forward\nLeft/Right: Rotate" tutrial := "Space: Move forward\nLeft/Right: Rotate"
msg := fmt.Sprintf("FPS: %0.2f\n%s", ebiten.CurrentFPS(), tutrial) msg := fmt.Sprintf("FPS: %0.2f\n%s", ebiten.CurrentFPS(), tutrial)
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
@ -213,24 +214,16 @@ func main() {
} }
w, h := gophersImage.Size() w, h := gophersImage.Size()
const repeat = 5 const repeat = 5
repeatedGophersImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest) repeatedGophersImage, _ = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
for j := 0; j < repeat; j++ { for j := 0; j < repeat; j++ {
for i := 0; i < repeat; i++ { for i := 0; i < repeat; i++ {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(w*i), float64(h*j)) op.GeoM.Translate(float64(w*i), float64(h*j))
if err := repeatedGophersImage.DrawImage(gophersImage, op); err != nil { repeatedGophersImage.DrawImage(gophersImage, op)
log.Fatal(err)
}
} }
} }
groundWidth := screenWidth + 70 groundWidth := screenWidth + 70
groundImage, err = ebiten.NewImage(groundWidth, screenHeight*2/3+50, ebiten.FilterNearest) groundImage, _ = ebiten.NewImage(groundWidth, screenHeight*2/3+50, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
const fogHeight = 8 const fogHeight = 8
fogRGBA := image.NewRGBA(image.Rect(0, 0, groundWidth, fogHeight)) fogRGBA := image.NewRGBA(image.Rect(0, 0, groundWidth, fogHeight))
for j := 0; j < fogHeight; j++ { for j := 0; j < fogHeight; j++ {
@ -245,10 +238,7 @@ func main() {
fogRGBA.SetRGBA(i, j, clr) fogRGBA.SetRGBA(i, j, clr)
} }
} }
fogImage, err = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterNearest) fogImage, _ = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Air Ship (Ebiten Demo)"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Air Ship (Ebiten Demo)"); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -65,7 +65,9 @@ func update(screen *ebiten.Image) error {
case 240 < count: case 240 < count:
diff = float64(480-count) * 0.2 diff = float64(480-count) * 0.2
} }
if ebiten.IsRunningSlowly() {
return nil
}
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff}) screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5) op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)

View File

@ -198,7 +198,9 @@ func update(screen *ebiten.Image) error {
} }
musicPlayer.updateVolume() musicPlayer.updateVolume()
} }
if ebiten.IsRunningSlowly() {
return nil
}
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
x, y, w, h := playerBarRect() x, y, w, h := playerBarRect()
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))

View File

@ -89,6 +89,9 @@ func parseFont() error {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
screen.DrawImage(textImage, &ebiten.DrawImageOptions{}) screen.DrawImage(textImage, &ebiten.DrawImageOptions{})
return nil return nil
} }

View File

@ -49,6 +49,9 @@ func update(screen *ebiten.Image) error {
pressedButtons = append(pressedButtons, strconv.Itoa(int(b))) pressedButtons = append(pressedButtons, strconv.Itoa(int(b)))
} }
} }
if ebiten.IsRunningSlowly() {
return nil
}
str := `Gamepad str := `Gamepad
Axes: Axes:

View File

@ -70,6 +70,9 @@ func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeyX) { if ebiten.IsKeyPressed(ebiten.KeyX) {
valueInt++ valueInt++
} }
if ebiten.IsRunningSlowly() {
return nil
}
hueInt = clamp(hueInt, -256, 256) hueInt = clamp(hueInt, -256, 256)
saturationInt = clamp(saturationInt, 0, 256) saturationInt = clamp(saturationInt, 0, 256)
valueInt = clamp(valueInt, 0, 256) valueInt = clamp(valueInt, 0, 256)

View File

@ -37,6 +37,9 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
count++ count++
if ebiten.IsRunningSlowly() {
return nil
}
w, h := gophersImage.Size() w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2) op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)

View File

@ -88,7 +88,9 @@ func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) {
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
theViewport.Move() theViewport.Move()
if ebiten.IsRunningSlowly() {
return nil
}
updateGroundImage(groundImage) updateGroundImage(groundImage)
drawGroundImage(screen, groundImage) drawGroundImage(screen, groundImage)

View File

@ -90,6 +90,9 @@ func (p pressedKeysParts) Src(i int) (x0, y0, x1, y1 int) {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
const offsetX, offsetY = 24, 40 const offsetX, offsetY = 24, 40
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(offsetX, offsetY) op.GeoM.Translate(offsetX, offsetY)

View File

@ -180,6 +180,9 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
world.Progress() world.Progress()
if ebiten.IsRunningSlowly() {
return nil
}
world.DrawImage(noiseImage) world.DrawImage(noiseImage)
screen.ReplacePixels(noiseImage.Pix) screen.ReplacePixels(noiseImage.Pix)
return nil return nil

View File

@ -64,7 +64,9 @@ func update(screen *ebiten.Image) error {
spotLightY = -spotLightY + 2*maxY spotLightY = -spotLightY + 2*maxY
spotLightVY = -spotLightVY spotLightVY = -spotLightVY
} }
if ebiten.IsRunningSlowly() {
return nil
}
maskImage.Clear() maskImage.Clear()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}

View File

@ -37,6 +37,9 @@ var (
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio) op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
gophersRenderTarget.DrawImage(gophersImage, op) gophersRenderTarget.DrawImage(gophersImage, op)

View File

@ -58,6 +58,9 @@ func update(screen *ebiten.Image) error {
noiseImage.Pix[4*i+2] = uint8(x >> 8) noiseImage.Pix[4*i+2] = uint8(x >> 8)
noiseImage.Pix[4*i+3] = 0xff noiseImage.Pix[4*i+3] = 0xff
} }
if ebiten.IsRunningSlowly() {
return nil
}
screen.ReplacePixels(noiseImage.Pix) screen.ReplacePixels(noiseImage.Pix)
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS())) ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS()))
return nil return nil

View File

@ -62,7 +62,9 @@ func update(screen *ebiten.Image) error {
if drawn { if drawn {
count++ count++
} }
if ebiten.IsRunningSlowly() {
return nil
}
screen.DrawImage(canvasImage, nil) screen.DrawImage(canvasImage, nil)
msg := fmt.Sprintf("(%d, %d)", mx, my) msg := fmt.Sprintf("(%d, %d)", mx, my)

View File

@ -55,6 +55,9 @@ func (p parts) Src(i int) (x0, y0, x1, y1 int) {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
return nil
}
op := &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{
ImageParts: &parts{gophersImage}, ImageParts: &parts{gophersImage},
} }

View File

@ -207,7 +207,9 @@ func update(screen *ebiten.Image) error {
return err return err
} }
} }
if ebiten.IsRunningSlowly() {
return nil
}
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff}) screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
screen.DrawImage(imagePiano, nil) screen.DrawImage(imagePiano, nil)

View File

@ -37,6 +37,9 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
count++ count++
if ebiten.IsRunningSlowly() {
return nil
}
w, h := gophersImage.Size() w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2) op.GeoM.Translate(-float64(w)/2, -float64(h)/2)

View File

@ -99,6 +99,9 @@ func update(screen *ebiten.Image) error {
return err return err
} }
} }
if ebiten.IsRunningSlowly() {
return nil
}
msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS()) msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS())
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
if err := audioContext.Update(); err != nil { if err := audioContext.Update(); err != nil {

View File

@ -86,6 +86,10 @@ func update(screen *ebiten.Image) error {
ebiten.SetScreenSize(screenWidth, screenHeight) ebiten.SetScreenSize(screenWidth, screenHeight)
ebiten.SetScreenScale(screenScale) ebiten.SetScreenScale(screenScale)
if ebiten.IsRunningSlowly() {
return nil
}
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff}) screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
w, h := gophersImage.Size() w, h := gophersImage.Size()
w2, h2 := screen.Size() w2, h2 := screen.Size()