-
-
Notifications
You must be signed in to change notification settings - Fork 677
Mobile
Ebiten game can be built for Android and iOS by using gomobile bind
, which generates a shared library file (aar on Android or .framework on iOS). Note that Ebiten doesn't accept gomobile build
, which generates an application file (apk on Android or ipa on iOS). Why Ebiten only uses gomobile bind
is because gomobile build
is difficult to build an actual application in Play store. gomobile build
is very easy to use to generate an application written only in Go, but the application includes only one OpenGL surface. Even if you want to an advertisement or use inputting via the keyboard, it is almost impossible. On the other hand, gomobile bind
generates a shared library and you'd need some glue Java code to use this, but that offers flexibility where you can do everything.
Inovation 2007 is an actual Android/iOS game using Ebiten. This application has been released in Play Store and Apple Store.
You need to create a package for mobiles with github.com/hajimehoshi/ebiten/mobile
for your game. This package has exported functions to Java/Objetive-C side.
For an actual example, see github.com/hajimehoshi/go-inovation/mobile/mobile.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/Objetive-C side by adding arguments to this function if
// you want to make Java/Objective-C side decide the screen size.
// Note that the screen size unit is dp (device-independent pixel)
// on Android.
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 on Android.
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
mobile.UpdateTouchesOnAndroid(action, id, x, y)
}
// UpdateTouchesOnIOS dispatches touch events on iOS.
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)
}