add sprite to window
This commit is contained in:
26
main.go
26
main.go
@@ -2,12 +2,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
|
_ "image/png"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
"github.com/faiface/pixel"
|
||||||
"github.com/faiface/pixel/pixelgl"
|
"github.com/faiface/pixel/pixelgl"
|
||||||
"golang.org/x/image/colornames"
|
"golang.org/x/image/colornames"
|
||||||
//"github.com/go-gl/glfw/v3.2/glfw"
|
//"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func loadPicture(path string) (pixel.Picture, error) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
img, _, err := image.Decode(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pixel.PictureDataFromImage(img), nil
|
||||||
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
cfg := pixelgl.WindowConfig{
|
cfg := pixelgl.WindowConfig{
|
||||||
Title: "Pixel Rocks!",
|
Title: "Pixel Rocks!",
|
||||||
@@ -20,7 +38,15 @@ func run() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pic, err := loadPicture("hiking.png")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite := pixel.NewSprite(pic, pic.Bounds())
|
||||||
|
|
||||||
win.Clear(colornames.Skyblue)
|
win.Clear(colornames.Skyblue)
|
||||||
|
sprite.Draw(win, pixel.IM)
|
||||||
|
|
||||||
for !win.Closed() {
|
for !win.Closed() {
|
||||||
win.Update()
|
win.Update()
|
||||||
|
|||||||
Reference in New Issue
Block a user