-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Game loop must wait until audio is initialized to avoid desynchronization between graphics and audio. On the web audio is initialized only after user action (such as clicking the mouse button). Show the "Play" image button to the user in such case.
- Loading branch information
Showing
6 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// (c) 2022-2023 Jacek Olszak | ||
// This code is licensed under MIT license (see LICENSE for details) | ||
|
||
package ebitengine | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"image/png" | ||
|
||
"github.com/hajimehoshi/ebiten/v2" | ||
) | ||
|
||
//go:embed "play.png" | ||
var playButton []byte | ||
|
||
var playButtonImage *ebiten.Image | ||
|
||
func init() { | ||
img, err := png.Decode(bytes.NewReader(playButton)) | ||
if err != nil { | ||
panic("decoding play.png failed: " + err.Error()) | ||
} | ||
playButtonImage = ebiten.NewImageFromImage(img) | ||
} | ||
|
||
// in web browser user action is needed to initialize audio - such as clicking the mouse or hitting the keyboard. | ||
// To inform the user that his action is needed drawNotReady draws a play button. | ||
func (e *game) drawNotReady(screen *ebiten.Image) { | ||
screenSize := screen.Bounds().Max | ||
screenWidth := screenSize.X | ||
screenHeight := screenSize.Y | ||
|
||
imageSize := playButtonImage.Bounds() | ||
imageWidth := imageSize.Max.X | ||
imageHeight := imageSize.Max.Y | ||
|
||
m := ebiten.GeoM{} | ||
m.Translate(float64(screenWidth-imageWidth)/2.0, float64(screenHeight-imageHeight)/2.0) | ||
|
||
screen.DrawImage(playButtonImage, &ebiten.DrawImageOptions{GeoM: m}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// (c) 2022-2023 Jacek Olszak | ||
// This code is licensed under MIT license (see LICENSE for details) | ||
|
||
//go:build !js | ||
|
||
package ebitengine | ||
|
||
import "github.com/hajimehoshi/ebiten/v2" | ||
|
||
// on non-js operating systems, initialization takes only few milliseconds and there is no user action needed. | ||
// Therefore, there is no need to draw anything. | ||
func (e *game) drawNotReady(*ebiten.Image) {} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.