generated from sionleroux/ebitengine-game-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
zoom.go
42 lines (37 loc) · 896 Bytes
/
zoom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/tanema/gween"
"github.com/tanema/gween/ease"
)
const zoomOutLevel = 1.0
const zoomInLevel = 1.5
const zoomTime = 15
// Zoom controls the camera zoom effect
type Zoom struct {
On bool
Amount float64
tweenIn *gween.Tween
tweenOut *gween.Tween
dt int
}
// NewZoom sets up a new zoom state tracker
func NewZoom() *Zoom {
return &Zoom{
On: false,
Amount: zoomOutLevel,
tweenIn: gween.New(zoomOutLevel, zoomInLevel, zoomTime, ease.OutCubic),
tweenOut: gween.New(zoomInLevel, zoomOutLevel, zoomTime, ease.OutCubic),
}
}
// Update updates the camera with the current zoom level
func (zoom *Zoom) Update() {
if zoom.On {
zoom.tweenOut.Reset()
amount, _ := zoom.tweenIn.Update(1)
zoom.Amount = float64(amount)
} else {
zoom.tweenIn.Reset()
amount, _ := zoom.tweenOut.Update(1)
zoom.Amount = float64(amount)
}
}