Updated Android (markdown)

Hajime Hoshi 2016-07-08 03:18:03 +09:00
parent f163dbf888
commit 72f4835b44

@ -13,7 +13,7 @@ You need to create a module for mobiles with `github.com/hajimehoshi/ebiten/mobi
For an actual example, see [`github.com/hajimehoshi/go-inovation/mobile/mobile.go`](https://github.com/hajimehoshi/go-inovation/blob/master/mobile/mobile.go). 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 ```go
package yourgame package mobile
import ( import (
"github.com/hajimehoshi/ebiten/mobile" "github.com/hajimehoshi/ebiten/mobile"
@ -73,7 +73,7 @@ func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
Use `gomobile bind`, generate an aar file and import this to your Android Studio project as an external aar file. Here is the example command to build the module. Use `gomobile bind`, generate an aar file and import this to your Android Studio project as an external aar file. Here is the example command to build the module.
```sh ```sh
:; gomobile bind -target android -javapkg com.example.yourgame.go -o /path/to/android/studio/project/mobile.aar github.com/yourname/yourgame/mobile :; gomobile bind -target android -javapkg com.example.yourgame -o /path/to/android/studio/project/mobile.aar github.com/yourname/yourgame/mobile
``` ```
## Implement Java classes ## Implement Java classes
@ -95,8 +95,6 @@ import android.view.View;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import com.example.yourgame.go.Yourgame;
public class EbitenGLSurfaceView extends GLSurfaceView { public class EbitenGLSurfaceView extends GLSurfaceView {
private class EbitenRenderer implements Renderer { private class EbitenRenderer implements Renderer {
@ -111,7 +109,7 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
try { try {
// onDrawFrame is called every frame. // onDrawFrame is called every frame.
// Let's call your game's Update. // Let's call your game's Update.
Yourgame.Update(); Mobile.Update();
} catch (Exception e) { } catch (Exception e) {
Log.e("Go Error", e.toString()); Log.e("Go Error", e.toString());
mErrored = true; mErrored = true;
@ -158,8 +156,8 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
public double getScaleInPx() { public double getScaleInPx() {
View parent = (View)getParent(); View parent = (View)getParent();
return Math.max(1, return Math.max(1,
Math.min(parent.getWidth() / (double)Yourgame.ScreenWidth, Math.min(parent.getWidth() / (double)Mobile.ScreenWidth,
parent.getHeight() / (double)Yourgame.ScreenHeight)); parent.getHeight() / (double)Mobile.ScreenHeight));
} }
@Override @Override
@ -167,11 +165,11 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
// Calculate the scale fitting the screen and use it. // Calculate the scale fitting the screen and use it.
double scaleInPx = getScaleInPx(); double scaleInPx = getScaleInPx();
getLayoutParams().width = (int)(Yourgame.ScreenWidth * scaleInPx); getLayoutParams().width = (int)(Mobile.ScreenWidth * scaleInPx);
getLayoutParams().height = (int)(Yourgame.ScreenHeight * scaleInPx); getLayoutParams().height = (int)(Mobile.ScreenHeight * scaleInPx);
try { try {
if (!Yourgame.IsRunning()) { if (!Mobile.IsRunning()) {
Yourgame.Start(pxToDp(scaleInPx)); Mobile.Start(pxToDp(scaleInPx));
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("Go Error", e.toString()); Log.e("Go Error", e.toString());
@ -188,7 +186,7 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
int y = (int)e.getY(i); int y = (int)e.getY(i);
// Call `mobile.UpdateTouchesOnAndroid` via your exported function. // Call `mobile.UpdateTouchesOnAndroid` via your exported function.
// The position is in dp. // The position is in dp.
Yourgame.UpdateTouchesOnAndroid(e.getActionMasked(), id, (int)pxToDp(x), (int)pxToDp(y)); Mobile.UpdateTouchesOnAndroid(e.getActionMasked(), id, (int)pxToDp(x), (int)pxToDp(y));
} }
return true; return true;
} }