Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 所有设备的精灵大小_Java_Android_Andengine_Sprite - Fatal编程技术网

Java 所有设备的精灵大小

Java 所有设备的精灵大小,java,android,andengine,sprite,Java,Android,Andengine,Sprite,如何为所有设备设置精灵大小?我用这个做雪碧: final Display display = getWindowManager().getDefaultDisplay(); CAMERA_WIDTH = display.getWidth(); CAMERA_HEIGHT = display.getHeight(); Log.e(Integer.toString(CAMERA_WIDTH), Integer.toString(CAMERA_HEIGHT));

如何为所有设备设置精灵大小?我用这个做雪碧:

    final Display display = getWindowManager().getDefaultDisplay();
    CAMERA_WIDTH = display.getWidth();
    CAMERA_HEIGHT = display.getHeight();
    Log.e(Integer.toString(CAMERA_WIDTH), Integer.toString(CAMERA_HEIGHT));
    camera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);




            facebook = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            this.mBitmapTextureAtlas, this, "facebook.png", 0, 0);


             mHardware1[active] = new Sprite(pX, pY, facebook,
                this.getVertexBufferObjectManager());
但当我在屏幕更小的设备上运行游戏时,精灵的大小保持不变。如何克服这个问题?

尝试在您的雪碧尺寸上使用“dp”单位。如果您使用“px”,它将不会在其他设备上扩展


更多详情请阅读:)

评论中@Siddharth给出的答案是正确的。在AndEngine中,您不应该自行缩放精灵以适应屏幕大小。相反,您应该使用内置和引擎功能来相应地缩放整个场景

@Override
public EngineOptions onCreateEngineOptions() {
    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    camera.setCenter(0, 0);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(.CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
现在,当您将
CAMERA\u WIDTH
CAMERA\u HEIGHT
设置为1280x720且精灵大小为640x360时,引擎将向上或向下缩放整个场景,包括任何屏幕上的精灵至1280x720。您的精灵将始终占据屏幕的四分之一。

替换

 new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT)
用这个

new FillResolutionPolicy()

使用FillResolutionPolicy,您只需要在一个维度上工作,它会自动调整所有设备的大小

px和py是位置而不是大小(您误解了我的解释:)),我的意思是,您必须设置图像密度,可以使用setDensity()或类似的方法。在该大小设置中,使用“dp”而不是“px”。当然,我知道
pX
pY
是你精神的位置。如果你使用的是比率解决方案策略,那么你就不必为此费心了;CAMERA_WIDTH=display.getWidth();摄像头高度=display.getHeight();Log.e(Integer.toString(摄像头宽度)、Integer.toString(摄像头高度));camera=新边界camera(0,0,camera\u宽度,camera\u高度);返回新引擎选项(true、ScreenOrientation.横向固定、新比率解决方案策略(摄像头宽度、摄像头高度)、摄像头);如果要在所有设备上获得相同的结果,请在从设计师处开发图形(如800x480或1024x600)时使用相机宽度和相机高度。