-
Notifications
You must be signed in to change notification settings - Fork 0
/
introText.go
99 lines (85 loc) · 2.03 KB
/
introText.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package gophengine
import (
"image/color"
"io/fs"
"sync"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text/v2"
)
type IntroText struct {
textLock sync.RWMutex
text []string
fullFace text.Face
outlineFace text.Face
}
func NewIntroText(fsys fs.FS) (*IntroText, error) {
fullFile, err := fsys.Open("fonts/phantom-full.ttf")
if err != nil {
return nil, err
}
defer fullFile.Close()
fullFaceSrc, err := text.NewGoTextFaceSource(fullFile)
if err != nil {
return nil, err
}
outlineFile, err := fsys.Open("fonts/phantom-outline.ttf")
if err != nil {
return nil, err
}
defer outlineFile.Close()
outlineFaceSrc, err := text.NewGoTextFaceSource(outlineFile)
if err != nil {
return nil, err
}
return &IntroText{
text: []string{},
fullFace: &text.GoTextFace{
Source: fullFaceSrc,
Direction: text.DirectionLeftToRight,
Size: 64,
},
outlineFace: &text.GoTextFace{
Source: outlineFaceSrc,
Direction: text.DirectionLeftToRight,
Size: 64,
},
}, nil
}
func (it *IntroText) Update(dt float64) error {
return nil
}
func (it *IntroText) Draw(img *ebiten.Image) {
it.textLock.RLock()
for i, s := range it.text {
{
opts := &text.DrawOptions{}
opts.GeoM.Translate(float64(img.Bounds().Dx())/2, (float64(i)*60)+200)
opts.ColorScale.ScaleWithColor(color.White)
opts.PrimaryAlign = text.AlignCenter
text.Draw(img, s, it.fullFace, opts)
}
{
opts := &text.DrawOptions{}
opts.GeoM.Translate(float64(img.Bounds().Dx())/2, (float64(i)*60)+200)
opts.ColorScale.ScaleWithColor(color.Black)
opts.PrimaryAlign = text.AlignCenter
text.Draw(img, s, it.outlineFace, opts)
}
}
it.textLock.RUnlock()
}
func (it *IntroText) CreateText(text ...string) {
it.textLock.Lock()
it.text = append(it.text, text...)
it.textLock.Unlock()
}
func (it *IntroText) AddText(text string) {
it.textLock.Lock()
it.text = append(it.text, text)
it.textLock.Unlock()
}
func (it *IntroText) DeleteText() {
it.textLock.Lock()
it.text = []string{}
it.textLock.Unlock()
}