Commit 2fe782e3 authored by kenan's avatar kenan

居中显示

parent 48c0bbf6
...@@ -35,10 +35,10 @@ bool Game::Initialize() { ...@@ -35,10 +35,10 @@ bool Game::Initialize() {
#endif #endif
srand(time(0)); srand(time(0));
irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters(); irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters();
int screenH = android::getScreenHeight(app); int screenH = static_cast<int>(android::getScreenHeight(app));
int screenW = android::getScreenWidth(app); int screenW = static_cast<int>(android::getScreenWidth(app));
float sH = screenH / 1024.0; float sH = static_cast<float>(screenH / 1024.0);
float sW = screenW / 640.0; float sW = static_cast<float>(screenW / 640.0);
//取最小值 //取最小值
if(sH < sW){ if(sH < sW){
...@@ -61,13 +61,13 @@ bool Game::Initialize() { ...@@ -61,13 +61,13 @@ bool Game::Initialize() {
params.Bits = 24; params.Bits = 24;
params.ZBufferBits = 16; params.ZBufferBits = 16;
params.AntiAlias = 0; params.AntiAlias = 0;
int w = (int)(1024.0*xScale); //int w = (int)(1024.0*xScale);
int h = (int)(640.0*yScale); //int h = (int)(640.0*yScale);
params.WindowSize = irr::core::dimension2d<u32>(w, h); params.WindowSize = irr::core::dimension2d<u32>(0, 0);
//每一个元素得left和top都需要改 //每一个元素得left和top都需要改
xStart = (float)((screenH - w)/2.0); //xStart = (float)((screenH - w)/2.0);
yStart = (float)((screenW - h)/2.0); //yStart = (float)((screenW - h)/2.0);
params.WindowPosition = core::position2di((s32)xStart, (s32)yStart); //params.WindowPosition = core::position2di((s32)xStart, (s32)yStart);
#else #else
if(gameConf.use_d3d) if(gameConf.use_d3d)
params.DriverType = irr::video::EDT_DIRECT3D9; params.DriverType = irr::video::EDT_DIRECT3D9;
......
...@@ -27,4 +27,5 @@ android { ...@@ -27,4 +27,5 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation "me.weishu:free_reflection:2.1.0"
} }
...@@ -26,6 +26,7 @@ public abstract class GameApplication extends Application implements IrrlichtBri ...@@ -26,6 +26,7 @@ public abstract class GameApplication extends Application implements IrrlichtBri
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
sGameApplication = this; sGameApplication = this;
// Reflection.unseal(this);
// initSoundEffectPool(); // initSoundEffectPool();
} }
......
...@@ -20,6 +20,7 @@ import android.view.Gravity; ...@@ -20,6 +20,7 @@ import android.view.Gravity;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.FrameLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -211,9 +212,47 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -211,9 +212,47 @@ public class YGOMobileActivity extends NativeActivity implements
if (app().isImmerSiveMode()) { if (app().isImmerSiveMode()) {
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
app().attachGame(this); app().attachGame(this);
//游戏大小
int[] size = getGameSize();
getWindow().setLayout(size[0], size[1]);
} }
} }
private int[] getGameSize(){
//调整padding
float screenW = app().getScreenWidth();
float screenH = app().getScreenHeight();
float sH = screenH / 1024.0f;
float sW = screenW / 640.0f;
float xScale,yScale;
//取最小值
if(sH < sW){
xScale = sH;
yScale = sH;
} else {
xScale = sW;
yScale = sW;
}
int w = (int)(1024.0*xScale);
int h = (int)(640.0*yScale);
return new int[]{w, h};
}
@Override
public void setContentView(View view) {
int[] size = getGameSize();
int w = size[0];
int h = size[1];
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
FrameLayout layout = new FrameLayout(this);
lp.gravity = Gravity.CENTER;
layout.addView(view, lp);
getWindow().setLayout(w, h);
getWindow().setGravity(Gravity.CENTER);
super.setContentView(layout);
}
private void initExtraView() { private void initExtraView() {
mContentView = getWindow().getDecorView().findViewById(android.R.id.content); mContentView = getWindow().getDecorView().findViewById(android.R.id.content);
mGlobalComboBox = new ComboBoxCompat(this); mGlobalComboBox = new ComboBoxCompat(this);
......
...@@ -31,4 +31,5 @@ android { ...@@ -31,4 +31,5 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation "me.weishu:free_reflection:2.1.0"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment