gpt4 book ai didi

android - AndEngine - Sprite 不会在不同的设备上缩放

转载 作者:太空狗 更新时间:2023-10-29 16:20:40 25 4
gpt4 key购买 nike

代码:

这就是初始化相机的方式。
我',试图获得设备的分辨率,并根据它设置相机的宽度和高度。

     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 的设备上尝试过游戏; enter image description here

当我在分辨率为 800X480 的设备上尝试相同的代码时 enter image description here

我认为 Sprite 不会在更高分辨率的设备上缩放。
据我所知,引擎会原生缩放相机和 Sprite 。

那么为什么 Sprite 在这种情况下没有缩放?

我应该怎么做才能根据分辨率放大 Sprite ?

我也试过 FillResolutionPolicy。同样的事情。

我正在使用 andengine 的 TexturePackerExtension 和 SpriteSheets。

最佳答案

您想要一个具有固定宽度 和由设备屏幕纵横比计算的高度相机。将其与 FillResolutionPolicy 配对,您将获得所需的结果。

注意:

AndEngine doesn't scale Sprites for you, but you set the Camera so that the whole Scene appears scaled.

关于android - AndEngine - Sprite 不会在不同的设备上缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15820219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com