Updated Android (markdown)

Hajime Hoshi 2016-08-01 23:41:53 +09:00
parent 0fc25a700e
commit a7076202fd

@ -4,66 +4,7 @@ See the document [[Mobile]] for details common in Android and iOS.
## Create a package for mobiles ## Create a package for mobiles
You need to create a package for mobiles with `github.com/hajimehoshi/ebiten/mobile` for your game. This package has exported functions to Java side. See https://github.com/hajimehoshi/ebiten/wiki/Mobile#create-a-package-for-mobiles.
For an actual example, see [`github.com/hajimehoshi/go-inovation/mobile/mobile.go`](https://github.com/hajimehoshi/go-inovation/blob/master/mobile/mobile.go).
```go
package mobile
import (
"github.com/hajimehoshi/ebiten/mobile"
"github.com/yourname/yourgame"
)
var (
running bool
)
const (
ScreenWidth = 320
ScreenHeight = 240
)
// IsRunning returns a boolean value indicating whether the game is running.
func IsRunning() bool {
return running
}
// Start starts the game.
func Start(scale float64) error {
running = true
game, err := yourgame.NewGame()
if err != nil {
return err
}
// mobile.Start starts the game.
// In this function, scale is passed from Java side and pass it
// to mobile.Start. You can also receive the screen size from Java
// side by adding arguments to this function if you want to make
// Java side decide the screen size.
// Note that the screen size unit is dp (device-independent pixel).
if err := mobile.Start(game.Update, ScreenWidth, ScreenHeight, scale, "Your Game's Title"); err != nil {
return err
}
return nil
}
// Update proceeds the game.
func Update() error {
return mobile.Update()
}
// UpdateTouchesOnAndroid dispatches touch events.
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
mobile.UpdateTouchesOnAndroid(action, id, x, y)
}
func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
// Prepare this function if you also want to make your game run on iOS.
mobile.UpdateTouchesOnIOS(phase, ptr, x, y)
}
```
## Compile the package for mobile ## Compile the package for mobile