Introduce mobile module

This commit is contained in:
Hajime Hoshi 2016-05-19 01:49:57 +09:00
parent b1afe6aeb2
commit dd9ab5e45a
2 changed files with 53 additions and 0 deletions

36
mobile/run.go Normal file
View File

@ -0,0 +1,36 @@
package mobile
import (
"github.com/hajimehoshi/ebiten"
)
var chError <-chan error
// Start starts the game and returns immediately.
//
// Different from ebiten.Run, this invokes only the game loop and not the main (UI) loop.
func Start(f func(*ebiten.Image) error, width, height, scale int, title string) {
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
return
}
func LastErrorString() string {
select {
case err := <-chError:
return err.Error()
default:
return ""
}
}
func SetScreenSize(width, height int) {
// TODO: Implement this
}
func SetScreenScale(scale int) {
// TODO: Implement this
}
func Render() {
// TODO: Implement this
}

17
run.go
View File

@ -63,6 +63,23 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
return <-ch
}
// RunWithoutMainLoop runs the game, but don't call the loop on the main (UI) thread.
// Different from Run, this function returns immediately.
//
// Typically, Ebiten users don't have to call this directly.
// Instead, functions in github.com/hajimehoshi/ebiten/mobile module call this.
func RunWithoutMainLoop(f func(*Image) error, width, height, scale int, title string) <-chan error {
ch := make(chan error)
go func() {
g := newGraphicsContext(f)
if err := loop.Run(g, width, height, scale, title, FPS); err != nil {
ch <- err
}
close(ch)
}()
return nil
}
// SetScreenSize changes the (logical) size of the screen.
// This doesn't affect the current scale of the screen.
//