mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Refactoring Input
This commit is contained in:
parent
ef6d643438
commit
b0de4acaf4
@ -153,20 +153,16 @@ func main() {
|
||||
ch := currentUI.glutInputEventCh
|
||||
var inputState ebiten.InputState
|
||||
for {
|
||||
select {
|
||||
case event := <-ch:
|
||||
switch event.State {
|
||||
case GlutInputEventStateUp:
|
||||
inputState.IsTapped = false
|
||||
inputState.X = 0
|
||||
inputState.Y = 0
|
||||
case GlutInputEventStateDown:
|
||||
inputState.IsTapped = true
|
||||
inputState.X = event.X
|
||||
inputState.Y = event.Y
|
||||
}
|
||||
default:
|
||||
// do nothing
|
||||
event := <-ch
|
||||
switch event.State {
|
||||
case GlutInputEventStateUp:
|
||||
inputState.IsTapped = false
|
||||
inputState.X = 0
|
||||
inputState.Y = 0
|
||||
case GlutInputEventStateDown:
|
||||
inputState.IsTapped = true
|
||||
inputState.X = event.X
|
||||
inputState.Y = event.Y
|
||||
}
|
||||
input <- inputState
|
||||
}
|
||||
@ -182,11 +178,13 @@ func main() {
|
||||
go func() {
|
||||
frameTime := time.Duration(int64(time.Second) / int64(game.Fps()))
|
||||
update := time.Tick(frameTime)
|
||||
inputState := ebiten.InputState{}
|
||||
for {
|
||||
select {
|
||||
case inputState = <-input:
|
||||
case <-update:
|
||||
inputState := <-input
|
||||
game.Update(inputState)
|
||||
inputState = ebiten.InputState{}
|
||||
case gameDraw := <-draw:
|
||||
ch := make(chan interface{})
|
||||
s := &SyncDrawable{game, ch}
|
||||
|
Loading…
Reference in New Issue
Block a user