From 72f4835b44a64e08472f092bb506f984aa1b7870 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 8 Jul 2016 03:18:03 +0900 Subject: [PATCH] Updated Android (markdown) --- Android.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Android.md b/Android.md index aaefcb4..c500898 100644 --- a/Android.md +++ b/Android.md @@ -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). ```go -package yourgame +package mobile import ( "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. ```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 @@ -95,8 +95,6 @@ import android.view.View; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; -import com.example.yourgame.go.Yourgame; - public class EbitenGLSurfaceView extends GLSurfaceView { private class EbitenRenderer implements Renderer { @@ -111,7 +109,7 @@ public class EbitenGLSurfaceView extends GLSurfaceView { try { // onDrawFrame is called every frame. // Let's call your game's Update. - Yourgame.Update(); + Mobile.Update(); } catch (Exception e) { Log.e("Go Error", e.toString()); mErrored = true; @@ -158,8 +156,8 @@ public class EbitenGLSurfaceView extends GLSurfaceView { public double getScaleInPx() { View parent = (View)getParent(); return Math.max(1, - Math.min(parent.getWidth() / (double)Yourgame.ScreenWidth, - parent.getHeight() / (double)Yourgame.ScreenHeight)); + Math.min(parent.getWidth() / (double)Mobile.ScreenWidth, + parent.getHeight() / (double)Mobile.ScreenHeight)); } @Override @@ -167,11 +165,11 @@ public class EbitenGLSurfaceView extends GLSurfaceView { super.onLayout(changed, left, top, right, bottom); // Calculate the scale fitting the screen and use it. double scaleInPx = getScaleInPx(); - getLayoutParams().width = (int)(Yourgame.ScreenWidth * scaleInPx); - getLayoutParams().height = (int)(Yourgame.ScreenHeight * scaleInPx); + getLayoutParams().width = (int)(Mobile.ScreenWidth * scaleInPx); + getLayoutParams().height = (int)(Mobile.ScreenHeight * scaleInPx); try { - if (!Yourgame.IsRunning()) { - Yourgame.Start(pxToDp(scaleInPx)); + if (!Mobile.IsRunning()) { + Mobile.Start(pxToDp(scaleInPx)); } } catch (Exception e) { Log.e("Go Error", e.toString()); @@ -188,7 +186,7 @@ public class EbitenGLSurfaceView extends GLSurfaceView { int y = (int)e.getY(i); // Call `mobile.UpdateTouchesOnAndroid` via your exported function. // 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; }