mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/edge: Update
This commit is contained in:
parent
98054928ac
commit
6929c70c06
@ -17,11 +17,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -37,7 +39,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
|
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
||||||
|
angle--
|
||||||
|
}
|
||||||
|
if ebiten.IsKeyPressed(ebiten.KeyRight) {
|
||||||
angle++
|
angle++
|
||||||
|
}
|
||||||
angle %= 360
|
angle %= 360
|
||||||
if err := screen.Fill(color.White); err != nil {
|
if err := screen.Fill(color.White); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -45,16 +52,20 @@ func update(screen *ebiten.Image) error {
|
|||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(-float64(colorImageWidth)/2, -float64(colorImageHeight)/2)
|
op.GeoM.Translate(-float64(colorImageWidth)/2, -float64(colorImageHeight)/2)
|
||||||
op.GeoM.Rotate(float64(angle) * math.Pi / 180)
|
op.GeoM.Rotate(float64(angle) * math.Pi / 180)
|
||||||
|
op.GeoM.Scale(4, 4)
|
||||||
op.GeoM.Translate(screenWidth/2, screenHeight/2)
|
op.GeoM.Translate(screenWidth/2, screenHeight/2)
|
||||||
if err := screen.DrawImage(colorImage, op); err != nil {
|
if err := screen.DrawImage(colorImage, op); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("Angle: %d [deg]", angle)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
colorImage, err = ebiten.NewImage(colorImageWidth, colorImageHeight, ebiten.FilterLinear)
|
colorImage, err = ebiten.NewImage(colorImageWidth, colorImageHeight, ebiten.FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user