-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgchangeevent.go
47 lines (40 loc) · 1.31 KB
/
bgchangeevent.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
43
44
45
46
47
package core
import (
"sync"
// "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
// this event change background of the scene and animate it a bit
type BGChangeEvent struct {
bg *ebiten.Image
// start position
Sx float64
Sy float64
// target position
Tx float64
Ty float64
Speed float64
Shader *ebiten.Shader
}
func NewBGChangeEventFromPath(imagepath string, moveParam MoveParam, imageloader ImageLoader, shader *ShaderParam) Event {
image, _ := imageloader.GetImage(imagepath)
if shader == nil {
return &BGChangeEvent{bg: image, Shader: nil, Sx: moveParam.Sx, Sy: moveParam.Sy, Tx: moveParam.Tx, Ty: moveParam.Ty, Speed: moveParam.Speed}
}
if shader.Shader != nil {
return &BGChangeEvent{bg: image, Shader: shader.Shader, Sx: moveParam.Sx, Sy: moveParam.Sy, Tx: moveParam.Tx, Ty: moveParam.Ty, Speed: moveParam.Speed}
} else {
sh, _ := GetShaderPool().GetShader(shader.ShaderName)
return &BGChangeEvent{bg: image, Shader: sh, Sx: moveParam.Sx, Sy: moveParam.Sy, Tx: moveParam.Tx, Ty: moveParam.Ty, Speed: moveParam.Speed}
}
}
func (b *BGChangeEvent) Execute(scene *Scene) {
img := MovableImage{image: b.bg, mutex: &sync.Mutex{}, Shader: b.Shader}
moveAnim := MoveAnimation{
tx: b.Tx,
ty: b.Ty,
Speed: b.Speed,
}
img.AddAnimation(&moveAnim)
scene.CurrentBg = &img
}