diff --git a/example/game/rects/rects.go b/example/game/rects/rects.go index 66c4d3cf5..f4fca7f62 100644 --- a/example/game/rects/rects.go +++ b/example/game/rects/rects.go @@ -11,12 +11,12 @@ import ( ) type Rects struct { - rectTextureId graphics.RenderTargetId - rectTextureInited bool - offscreenId graphics.RenderTargetId - offscreenInited bool - rectBounds *graphics.Rect - rectColor *color.RGBA + rectTextureId graphics.RenderTargetId + rectTextureInited bool + offscreenId graphics.RenderTargetId + offscreenInited bool + rectBounds *graphics.Rect + rectColor *color.RGBA screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent screenWidth int screenHeight int @@ -31,10 +31,10 @@ const ( func New() *Rects { return &Rects{ - rectTextureInited: false, - offscreenInited: false, - rectBounds: &graphics.Rect{}, - rectColor: &color.RGBA{}, + rectTextureInited: false, + offscreenInited: false, + rectBounds: &graphics.Rect{}, + rectColor: &color.RGBA{}, screenSizeUpdatedCh: make(chan ebiten.ScreenSizeUpdatedEvent), } } diff --git a/example/game/rotating/rotating.go b/example/game/rotating/rotating.go index 58d94a316..535c76320 100644 --- a/example/game/rotating/rotating.go +++ b/example/game/rotating/rotating.go @@ -16,9 +16,9 @@ const ( ) type Rotating struct { - ebitenTextureId graphics.TextureId - x int - geometryMatrix matrix.Geometry + ebitenTextureId graphics.TextureId + x int + geometryMatrix matrix.Geometry screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent screenWidth int screenHeight int diff --git a/example/game/sprites/sprites.go b/example/game/sprites/sprites.go index 3d9c49528..ec999b9eb 100644 --- a/example/game/sprites/sprites.go +++ b/example/game/sprites/sprites.go @@ -64,8 +64,8 @@ func (sprite *Sprite) Update() { } type Sprites struct { - ebitenTextureId graphics.TextureId - sprites []*Sprite + ebitenTextureId graphics.TextureId + sprites []*Sprite screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent screenWidth int screenHeight int diff --git a/example/main.go b/example/main.go index 30be6cfdf..4c66b561d 100644 --- a/example/main.go +++ b/example/main.go @@ -81,20 +81,26 @@ func main() { events: for { select { - case e := <-screenSizeUpdated: - type Handler interface { - OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent) + case e, ok := <-inputStateUpdated: + if ok { + type Handler interface { + OnInputStateUpdated(ebiten.InputStateUpdatedEvent) + } + if game2, ok := game.(Handler); ok { + game2.OnInputStateUpdated(e) + } } - if game2, ok := game.(Handler); ok { - game2.OnScreenSizeUpdated(e) - } - case e := <-inputStateUpdated: - type Handler interface { - OnInputStateUpdated(ebiten.InputStateUpdatedEvent) - } - if game2, ok := game.(Handler); ok { - game2.OnInputStateUpdated(e) + inputStateUpdated = ui.ObserveInputStateUpdated() + case e, ok := <-screenSizeUpdated: + if ok { + type Handler interface { + OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent) + } + if game2, ok := game.(Handler); ok { + game2.OnScreenSizeUpdated(e) + } } + screenSizeUpdated = ui.ObserveScreenSizeUpdated() default: break events } diff --git a/ui/cocoa/cocoa.go b/ui/cocoa/cocoa.go index 7bb3529a9..970f8d583 100644 --- a/ui/cocoa/cocoa.go +++ b/ui/cocoa/cocoa.go @@ -47,9 +47,9 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI { panic("UI can't be duplicated.") } ui := &UI{ - screenWidth: screenWidth, - screenHeight: screenHeight, - screenScale: screenScale, + screenWidth: screenWidth, + screenHeight: screenHeight, + screenScale: screenScale, initialEventSent: false, inputStateUpdatedChs: make(chan chan ebiten.InputStateUpdatedEvent), inputStateUpdatedNotified: make(chan ebiten.InputStateUpdatedEvent), @@ -90,13 +90,17 @@ func (ui *UI) chLoop() { case e := <-ui.inputStateUpdatedNotified: for _, ch := range inputStateUpdated { ch <- e + close(ch) } + inputStateUpdated = []chan ebiten.InputStateUpdatedEvent{} case ch := <-ui.screenSizeUpdatedChs: screenSizeUpdated = append(screenSizeUpdated, ch) case e := <-ui.screenSizeUpdatedNotified: for _, ch := range screenSizeUpdated { ch <- e + close(ch) } + screenSizeUpdated = []chan ebiten.ScreenSizeUpdatedEvent{} } } }