這是如何初始化攝像頭。
我',試圖獲得設備的分辨率和基於我設置相機的寬度和高度。
public class GameActivity extends SimpleBaseGameActivity {
private SmoothCamera mCamera;
private DisplayMetrics dM;
private int CAMERA_WIDTH, CAMERA_HEIGHT;
private double ScreenWidth,
ScreenHeight,
resolutionRatio;
public EngineOptions onCreateEngineOptions() {
//set Camera
getDeviceResolution();
setCamera();
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED,
new RatioResolutionPolicy((int)this.getCameraWidth(),(int)this.getCameraHeight()),
//new FillResolutionPolicy(),
mCamera);
return options;
}
private void getDeviceResolution() {
dM = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dM);
this.ScreenWidth = dM.widthPixels;
this.ScreenHeight = dM.heightPixels;
this.resolutionRatio = this.ScreenWidth/this.ScreenHeight;
resolutionRatio = (double)Math.round(resolutionRatio * 100)/100;
Log.d("Resolution","ScrennWidth: "+this.ScreenWidth);
Log.d("Resolution","ScrennHeight: "+this.ScreenHeight);
Log.d("Resolution","Resolution Ratio: " + this.resolutionRatio);
}
private void setCamera() {
if(resolutionRatio == 1.66){
this.setCameraHeight(340);
this.setCameraWidth(400);
}else if(resolutionRatio == 2.13){
this.setCameraHeight(480);
this.setCameraWidth(1024);
}else if(resolutionRatio == 1.77){
this.setCameraHeight(720);
this.setCameraWidth(1280);
}else if(resolutionRatio == 1.5){
this.setCameraHeight(320);
this.setCameraWidth(480);
}else if(resolutionRatio == 1.67){
this.setCameraHeight(480);
this.setCameraWidth(800);
}else {
this.setCameraHeight((int) this.ScreenHeight);
this.setCameraWidth((int) this.ScreenWidth);
}
// Create a Camera
this.mCamera = new SmoothCamera(0,0,(int)getCameraWidth(),(int)getCameraHeight(),100,100,1.0f);
mCamera.setZoomFactor(1.0f);
mCamera.setBoundsEnabled(true);
mCamera.setBounds(0, 0, mCamera.getWidth(), mCamera.getHeight());
}
}
問題是。
我已經在480x320分辨率的設備上玩遊戲;
,當我與800X480
分辨率上設備嘗試相同的代碼本人認爲精靈沒有得到較高分辨率的設備縮放。
據我所知,andengine本身就會縮放攝像頭和精靈。
那麼爲什麼精靈不能在這種情況下縮放呢?
我應該怎麼做才能根據分辨率放大精靈?
我也試過FillResolutionPolicy。一樣。
我正在使用andengine和SpriteSheets的TexturePackerExtension。
FillResolutionPolicy並修復相機大小組合工作! :d – 2013-04-09 12:00:00