mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
examples/fullscreen: handle F key to enter fullscreen
On browsers, fullscreen requires an explicit user input.
This commit is contained in:
parent
063960c9bd
commit
d6fe8ed694
@ -26,6 +26,7 @@ import (
|
|||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
"golang.org/x/image/font/opentype"
|
"golang.org/x/image/font/opentype"
|
||||||
@ -78,6 +79,9 @@ type Game struct {
|
|||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
g.count++
|
g.count++
|
||||||
|
|
||||||
|
if runtime.GOOS == "js" && ebiten.IsKeyPressed(ebiten.KeyF) {
|
||||||
|
ebiten.SetFullscreen(true)
|
||||||
|
}
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyQ) {
|
if ebiten.IsKeyPressed(ebiten.KeyQ) {
|
||||||
return regularTermination
|
return regularTermination
|
||||||
}
|
}
|
||||||
@ -99,16 +103,15 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
screen.DrawImage(gophersImage, op)
|
screen.DrawImage(gophersImage, op)
|
||||||
|
|
||||||
fw, fh := ebiten.ScreenSizeInFullscreen()
|
fw, fh := ebiten.ScreenSizeInFullscreen()
|
||||||
msgs := []string{
|
msg := "This is an example of the finest fullscreen. Press Q to quit.\n"
|
||||||
"This is an example of the finest fullscreen. Press Q to quit.",
|
if runtime.GOOS == "js" {
|
||||||
fmt.Sprintf("Screen size in fullscreen: %d, %d", fw, fh),
|
msg += "Press F to enter fullscreen (again).\n"
|
||||||
fmt.Sprintf("Game's screen size: %d, %d", sw, sh),
|
|
||||||
fmt.Sprintf("Device scale factor: %0.2f", scale),
|
|
||||||
}
|
}
|
||||||
|
msg += fmt.Sprintf("Screen size in fullscreen: %d, %d\n", fw, fh)
|
||||||
|
msg += fmt.Sprintf("Game's screen size: %d, %d\n", sw, sh)
|
||||||
|
msg += fmt.Sprintf("Device scale factor: %0.2f\n", scale)
|
||||||
|
|
||||||
for i, msg := range msgs {
|
text.Draw(screen, msg, mplusFont, int(50*scale), 50, color.White)
|
||||||
text.Draw(screen, msg, mplusFont, int(50*scale), int(50+float64(i)*16*scale), color.White)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user