Skip to content

Commit

Permalink
demo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
setanarut committed Sep 27, 2024
1 parent 00dd374 commit 262a5df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions examples/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
package main

import (
"bytes"
"image"
"image/color"
_ "image/jpeg"
"log"
"math/rand/v2"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/vector"
"github.com/setanarut/kamera/v2"
Expand All @@ -28,16 +31,15 @@ var (
| R | Rotate |
| L | Toggle Lerp |
`
w, h float64 = 700, 532
w, h float64 = 1024, 768
camSpeed, zoomSpeedFactor, rotSpeed float64 = 1.01, 1.02, 0.02
targetX, targetY float64 = w / 2, h / 2
cam *kamera.Camera = kamera.NewCamera(targetX, targetY, w, h)
dio *ebiten.DrawImageOptions = &ebiten.DrawImageOptions{}
img *ebiten.Image
gophersImage *ebiten.Image
)

func init() {
img, _, _ = ebitenutil.NewImageFromFile("polen.jpg")
cam.Lerp = true
}

Expand Down Expand Up @@ -102,7 +104,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {

// Draw camera
cam.Draw(img, dio, screen)
cam.Draw(gophersImage, dio, screen)

// Draw camera crosshair
cx, cy := float32(w/2), float32(h/2)
Expand All @@ -118,7 +120,11 @@ func (g *Game) Layout(width, height int) (int, int) {
}

func main() {

img, _, err := image.Decode(bytes.NewReader(images.Spritesheet_png))
if err != nil {
log.Fatal(err)
}
gophersImage = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(int(w), int(h))
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
Expand Down
Binary file removed examples/demo/polen.jpg
Binary file not shown.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ require (
golang.org/x/sys v0.25.0 // indirect
)

retract [v2.0.0, v2.2.0]
retract (
v2.6.0 // nil pointer dereference (jpg) in demo code.
[v2.0.0, v2.2.0]
)

0 comments on commit 262a5df

Please sign in to comment.