Rotate sprite dynamically using delta time
This commit is contained in:
parent
736ffaa9da
commit
21406a1bfb
17
main.go
17
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
"github.com/faiface/pixel"
|
||||||
"github.com/faiface/pixel/pixelgl"
|
"github.com/faiface/pixel/pixelgl"
|
||||||
@ -37,6 +38,7 @@ func run() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
win.SetSmooth(true)
|
||||||
pic, err := loadPicture("hiking.png")
|
pic, err := loadPicture("hiking.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -44,10 +46,21 @@ func run() {
|
|||||||
|
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
sprite := pixel.NewSprite(pic, pic.Bounds())
|
||||||
|
|
||||||
win.Clear(colornames.Skyblue)
|
angle := 0.0
|
||||||
sprite.Draw(win, pixel.IM.Moved(win.Bounds().Center()))
|
last := time.Now()
|
||||||
|
|
||||||
for !win.Closed() {
|
for !win.Closed() {
|
||||||
|
dt := time.Since(last).Seconds()
|
||||||
|
last = time.Now()
|
||||||
|
|
||||||
|
angle += 3 * dt
|
||||||
|
|
||||||
|
win.Clear(colornames.Firebrick)
|
||||||
|
|
||||||
|
mat := pixel.IM
|
||||||
|
mat = mat.Rotated(pixel.ZV, angle)
|
||||||
|
mat = mat.Moved(win.Bounds().Center())
|
||||||
|
sprite.Draw(win, mat)
|
||||||
win.Update()
|
win.Update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user