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