-
Notifications
You must be signed in to change notification settings - Fork 136
/
button.go
43 lines (36 loc) · 901 Bytes
/
button.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
package engo
// A Button is an input which can be either JustPressed, JustReleased or Down. Common uses would be for, a jump key or an action key.
type Button struct {
Triggers []Key
Name string
}
// JustPressed checks whether an input was pressed in the previous frame.
func (b Button) JustPressed() bool {
for _, trigger := range b.Triggers {
v := Input.keys.Get(trigger).JustPressed()
if v {
return v
}
}
return false
}
// JustReleased checks whether an input was released in the previous frame.
func (b Button) JustReleased() bool {
for _, trigger := range b.Triggers {
v := Input.keys.Get(trigger).JustReleased()
if v {
return v
}
}
return false
}
// Down checks whether the current input is being held down.
func (b Button) Down() bool {
for _, trigger := range b.Triggers {
v := Input.keys.Get(trigger).Down()
if v {
return v
}
}
return false
}