Commit 480d4237 authored by kenan's avatar kenan

宽高

parent 728505f0
......@@ -37,8 +37,17 @@ bool Game::Initialize() {
irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters();
int screenH = android::getScreenHeight(app);
int screenW = android::getScreenWidth(app);
xScale = screenH / 1024.0;
yScale = screenW / 640.0;
float sH = screenH / 1024.0;
float sW = screenW / 640.0;
//取最小值
if(sH < sW){
xScale = sH;
yScale = sH;
} else {
xScale = sW;
yScale = sW;
}
#ifdef _IRR_ANDROID_PLATFORM_
android::InitOptions *options = android::getInitOptions(app);
......@@ -52,9 +61,11 @@ bool Game::Initialize() {
params.Bits = 24;
params.ZBufferBits = 16;
params.AntiAlias = 0;
params.WindowSize = irr::core::dimension2d<u32>(0, 0);
params.WindowLeft = (screenH - 1024.0*xScale)/2.0;
params.WindowTop = (screenW - 640.0*yScale)/2.0;
int w = 1024.0*xScale;
int h = 640.0*yScale;
params.WindowSize = irr::core::dimension2d<u32>(w, h);
params.WindowLeft = (screenH - w)/2.0;
params.WindowTop = (screenW - h)/2.0;
#else
if(gameConf.use_d3d)
params.DriverType = irr::video::EDT_DIRECT3D9;
......
......@@ -3,10 +3,12 @@ package cn.garymb.ygomobile;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Environment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import com.zlm.libs.preferences.PreferencesProviderUtils;
......@@ -78,10 +80,21 @@ public class AppsSettings {
return new File(getResourcePath(), CORE_SYSTEM_PATH);
}
private static float getScale(float srcWidth, float srcHeight, float destWidth, float destHeight) {
float sx = srcWidth / destWidth;
float sy = srcHeight == 0 ? (sx + 1.0f) : (srcHeight / destHeight);
return Math.min(sx, sy);
}
public void update(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point size = new Point();
//真实宽高
wm.getDefaultDisplay().getRealSize(size);
mDensity = context.getResources().getDisplayMetrics().density;
mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
mScreenHeight = size.y;
mScreenWidth = size.x;
if (isImmerSiveMode() && context instanceof Activity) {
DisplayMetrics dm = SystemUtils.getHasVirtualDisplayMetrics((Activity) context);
......@@ -458,7 +471,7 @@ public class AppsSettings {
public String getResourcePath() {
String defPath;
try {
defPath = new File(Environment.getExternalStorageDirectory(), Constants.PREF_DEF_GAME_DIR).getAbsolutePath();
defPath = new File(context.getExternalStorageDirectory(), Constants.PREF_DEF_GAME_DIR).getAbsolutePath();
} catch (Exception e) {
defPath = new File(context.getFilesDir(), Constants.PREF_DEF_GAME_DIR).getAbsolutePath();
}
......
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