代码 :
这就是我初始化相机的方式。
我',试图获得设备的分辨率,并在此基础上设置相机的宽度和高度。
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 的设备上尝试相同的代码时
我认为精灵没有在更高分辨率的设备上缩放。
据我所知,引擎可以原生缩放相机和精灵。
那么为什么精灵在这种情况下没有得到缩放呢?
我应该怎么做才能根据分辨率放大精灵?
我也试过 FillResolutionPolicy。一样。
我正在使用 andengine 和 SpriteSheets 的 TexturePackerExtension。