Skip to content

Commit bf6f9b9

Browse files
authored
V2.97.0 (#12)
* v2.97.0 - Fixed an issue where CenterOffset was not added when ShakeEnabled was true. - Update go.mod deps - Update Examples * update readme and examples
1 parent b230342 commit bf6f9b9

7 files changed

Lines changed: 161 additions & 126 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A pseudo code:
2424
```Go
2525
func (g *Game) Update() error {
2626
g.MainCamera.LookAt(player.X, player.Y)
27+
playerDrawImageOptions.GeoM.Reset()
2728
// Apply all world-space `playerDrawImageOptions.GeoM{}` transform here
2829
}
2930
func (g *Game) Draw(screen *ebiten.Image) {
@@ -46,4 +47,12 @@ Run director example on your local machine
4647

4748
```console
4849
go run github.com/setanarut/kamera/v2/examples/director@latest
50+
```
51+
52+
### Director (colorm package)
53+
54+
Run director_colorm example on your local machine
55+
56+
```console
57+
go run github.com/setanarut/kamera/v2/examples/director_colorm@latest
4958
```

camera.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ func (cam *Camera) LookAt(targetX, targetY float64) {
223223
cam.X = targetX
224224
cam.Y = targetY
225225
}
226+
case None:
227+
cam.X = targetX
228+
cam.Y = targetY
226229
default:
227230
cam.X = targetX
228231
cam.Y = targetY
@@ -255,6 +258,8 @@ func (cam *Camera) LookAt(targetX, targetY float64) {
255258
cam.ActualAngle += cam.Angle
256259
cam.X += cam.TraumaOffsetX
257260
cam.Y += cam.TraumaOffsetY
261+
cam.X += cam.CenterOffsetX
262+
cam.Y += cam.CenterOffsetY
258263

259264
// tick
260265
cam.Tick += cam.TickSpeed
@@ -329,6 +334,9 @@ func (cam *Camera) Reset() {
329334

330335
const cameraStats = `TargetX: %.2f
331336
TargetY: %.2f
337+
Top-left X: %.2f
338+
Top-left Y: %.2f
339+
Size: %.2f %.2f
332340
Cam Rotation: %.2f
333341
Zoom factor: %.2f
334342
ShakeEnabled: %v
@@ -356,6 +364,9 @@ func (cam *Camera) String() string {
356364
cameraStats,
357365
cam.X-cam.CenterOffsetX,
358366
cam.Y-cam.CenterOffsetY,
367+
cam.X,
368+
cam.Y,
369+
cam.Width, cam.Height,
359370
cam.ActualAngle,
360371
cam.ZoomFactorShake,
361372
cam.ShakeEnabled,

examples/director/main.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Backspace Reset camera
3333
R Rotate
3434
`
3535
w, h = 1024., 768.
36-
camSpeed, zoomSpeedFactor, rotSpeed = 7.0, 1.02, 0.02
37-
targetX, targetY = w / 2, h / 2
36+
camSpeed, zoomSpeedFactor, rotSpeed = 2.0, 1.02, 0.02
37+
targetX, targetY = 0., 0.
3838
cam = kamera.NewCamera(targetX, targetY, w, h)
3939
dio = &ebiten.DrawImageOptions{}
4040
spriteSheet *ebiten.Image
@@ -44,17 +44,6 @@ type Game struct{}
4444

4545
func (g *Game) Update() error {
4646

47-
aX, aY := Normalize(Axis())
48-
49-
targetX += aX * camSpeed
50-
targetY += aY * camSpeed
51-
52-
cam.LookAt(targetX, targetY)
53-
54-
if inpututil.IsKeyJustPressed(ebiten.KeyG) {
55-
cam.SetSize(500, 500)
56-
}
57-
5847
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
5948
cam.AddTrauma(1.0)
6049
}
@@ -67,7 +56,7 @@ func (g *Game) Update() error {
6756
}
6857

6958
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
70-
targetX, targetY = rand.Float64()*w, rand.Float64()*h
59+
targetX, targetY = rand.Float64()*200, rand.Float64()*200
7160
}
7261

7362
if inpututil.IsKeyJustPressed(ebiten.KeyTab) {
@@ -99,22 +88,26 @@ func (g *Game) Update() error {
9988
}
10089

10190
if ebiten.IsKeyPressed(ebiten.KeyBackspace) {
102-
targetX, targetY = w/2, h/2
91+
targetX, targetY = 0, 0
92+
cam.SetCenter(0, 0)
10393
cam.Reset()
10494
}
10595

96+
cam.LookAt(targetX, targetY)
97+
dio.GeoM.Reset()
98+
aX, aY := Normalize(Axis())
99+
aX *= camSpeed
100+
aY *= camSpeed
101+
102+
targetX += aX
103+
targetY += aY
104+
106105
return nil
107106
}
108107

109108
func (g *Game) Draw(screen *ebiten.Image) {
109+
cam.Draw(spriteSheet, dio, screen)
110110

111-
for y := 0; y < 4; y++ {
112-
for x := 0; x < 4; x++ {
113-
dio.GeoM.Reset()
114-
dio.GeoM.Translate(float64(x*300), float64(y*300))
115-
cam.Draw(spriteSheet, dio, screen)
116-
}
117-
}
118111
// Draw camera crosshair
119112
cx, cy := float32(w/2), float32(h/2)
120113
vector.StrokeLine(screen, cx-100, cy, cx+100, cy, 1, color.White, true)

examples/director_colorm/main.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,17 @@ Backspace Reset camera
3434
R Rotate
3535
`
3636
w, h = 1024., 768.
37-
camSpeed, zoomSpeedFactor, rotSpeed = 7.0, 1.02, 0.02
38-
targetX, targetY = w / 2, h / 2
37+
camSpeed, zoomSpeedFactor, rotSpeed = 2.0, 1.02, 0.02
38+
targetX, targetY = 0., 0.
3939
cam = kamera.NewCamera(targetX, targetY, w, h)
40-
colormDIO = &colorm.DrawImageOptions{}
40+
dio = &colorm.DrawImageOptions{}
4141
spriteSheet *ebiten.Image
4242
)
4343

4444
type Game struct{}
4545

4646
func (g *Game) Update() error {
4747

48-
aX, aY := Normalize(Axis())
49-
50-
targetX += aX * camSpeed
51-
targetY += aY * camSpeed
52-
53-
cam.LookAt(targetX, targetY)
54-
5548
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
5649
cam.AddTrauma(1.0)
5750
}
@@ -64,7 +57,7 @@ func (g *Game) Update() error {
6457
}
6558

6659
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
67-
targetX, targetY = rand.Float64()*w, rand.Float64()*h
60+
targetX, targetY = rand.Float64()*200, rand.Float64()*200
6861
}
6962

7063
if inpututil.IsKeyJustPressed(ebiten.KeyTab) {
@@ -96,27 +89,28 @@ func (g *Game) Update() error {
9689
}
9790

9891
if ebiten.IsKeyPressed(ebiten.KeyBackspace) {
99-
targetX, targetY = w/2, h/2
92+
targetX, targetY = 0, 0
93+
cam.SetCenter(0, 0)
10094
cam.Reset()
10195
}
10296

97+
cam.LookAt(targetX, targetY)
98+
dio.GeoM.Reset()
99+
aX, aY := Normalize(Axis())
100+
aX *= camSpeed
101+
aY *= camSpeed
102+
103+
targetX += aX
104+
targetY += aY
105+
103106
return nil
104107
}
105108

106109
func (g *Game) Draw(screen *ebiten.Image) {
107-
108110
var cm colorm.ColorM
109111

110112
cm.ChangeHSV(2, 1, 0.5)
111-
112-
// Draw backgorund tiles
113-
for y := 0; y < 4; y++ {
114-
for x := 0; x < 4; x++ {
115-
colormDIO.GeoM.Reset()
116-
colormDIO.GeoM.Translate(float64(x*300), float64(y*300))
117-
cam.DrawWithColorM(spriteSheet, cm, colormDIO, screen)
118-
}
119-
}
113+
cam.DrawWithColorM(spriteSheet, cm, dio, screen)
120114

121115
// Draw camera crosshair
122116
cx, cy := float32(w/2), float32(h/2)

0 commit comments

Comments
 (0)