mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Updated Android (markdown)
parent
2923732ace
commit
4495d27c0f
36
Android.md
36
Android.md
@ -78,6 +78,8 @@ Use `gomobile bind`, generate an aar file and import this to your Android Studio
|
||||
|
||||
## Implement a class inheriting GLSurfaceView
|
||||
|
||||
The below implementation implements a GLSurfaceView class. When the view's `onLayout` is called, the size of view is calculated and the game starts if the game doesn't start yet.
|
||||
|
||||
```java
|
||||
// ...
|
||||
import com.example.yourgame
|
||||
@ -110,8 +112,6 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
|
||||
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
// Calculate the scale fitting the screen and use it.
|
||||
// If you want to center this view, you can set `android:layout_centerHorizontal="true"` and
|
||||
// `android:layout_centerVertical="true"` in the layout XML.
|
||||
double scaleInPx = getScaleInPx();
|
||||
getLayoutParams().width = (int)(Yourgame.ScreenWidth * scaleInPx);
|
||||
getLayoutParams().height = (int)(Yourgame.ScreenHeight * scaleInPx);
|
||||
@ -128,6 +128,38 @@ public class EbitenGLSurfaceView extends GLSurfaceView {
|
||||
}
|
||||
```
|
||||
|
||||
If you want to center this view, you can set `android:layout_centerHorizontal="true"` and `android:layout_centerVertical="true"` in the layout XML.
|
||||
|
||||
## Implement a class implementing Renderer
|
||||
|
||||
Implement a Renderer class to use for the GLSurfaceView class defined below.
|
||||
|
||||
```java
|
||||
private class EbitenRenderer implements Renderer {
|
||||
|
||||
private boolean mErrored;
|
||||
|
||||
@Override
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
if (mErrored) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// onDrawFrame is called every frame.
|
||||
// Let's call your game's Update.
|
||||
Yourgame.Update();
|
||||
} catch (Exception e) {
|
||||
Log.e("Go Error", e.toString());
|
||||
mErrored = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Dispatch touch events
|
||||
|
||||
Call `mobile.UpdateTouchesOnAndroid` via your exported function.
|
||||
|
Loading…
Reference in New Issue
Block a user