不同屏幕尺寸和引擎 Android 上的精灵大小 [英] Sprite size on different screen size Andengine Android

查看:24
本文介绍了不同屏幕尺寸和引擎 Android 上的精灵大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

` 我正在 Android Adnengine 中开发我的第一个游戏.这是一款俯视图的赛车游戏.我使用了视差背景和一些汽车.我在宽度和高度较小的设备上对其进行了测试.

我根据相机的宽度、高度放置了 32 和高度 64 的汽车.它在我的屏幕尺寸下运行良好,但在更大的屏幕尺寸(如 Galaxy Tab)上,游戏中留下了巨大的空间,因为汽车尺寸保持不变,因为我必须以 2 的幂使用它们.

如何使用适合所有屏幕尺寸的图像?我是否必须根据不同相机宽度和高度的图像大小使用不同的图像?我相信有一个解决方案.

我已经修改了我的清单文件以支持小、大和超大尺寸.

 公共引擎 onLoadEngine() {最终显示 display = getWindowManager().getDefaultDisplay();CAMERA_WIDTH = display.getWidth();CAMERA_HEIGHT = display.getHeight();//Toast.makeText(getApplicationContext(), CAMERA_WIDTH, 3);mCamera = 新相机(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);引擎 = 新引擎(新引擎选项(真,ScreenOrientation.LANDSCAPE,新的 RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera).setNeedsMusic(真).setNeedsSound(真));返回引擎;}

解决方案

使用比率分辨率策略的好处是您可以将游戏设计为特定尺寸,例如 800x480,这在当今手机中非常流行.

我认为大多数人认为他们需要拉当前显示宽度/高度并使用它来初始化引擎.

比率分辨率策略的要点 - 据我所知 - 是您将尺寸设置为硬编码值,并让比率分辨率策略处理从一台设备到另一台设备的差异.

CAMERA_WIDTH = 800;相机高度 = 480;//Toast.makeText(getApplicationContext(), CAMERA_WIDTH, 3);mCamera = 新相机(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);引擎 = 新引擎(新引擎选项(真,ScreenOrientation.LANDSCAPE,新的 RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera).setNeedsMusic(真).setNeedsSound(真));

一旦你做了这样的事情,那么你只需要确保你的图形和间距在你预先选择的宽度/高度下看起来不错 - 在这个例子中是 800 x 480.如果一切正常并且适合并且看起来不错,那么比率当设备具有不同的屏幕尺寸时,分辨率政策会处理这些事情.

至少我对它应该如何工作的看法 - 我为 800 x 480 写作,而且在我的 7 英寸平板电脑上一切看起来也不错 - 当然这不是什么大问题.

` I am developing my first game in Android Adnengine. It's a racing game from top view. I used parallax background and some cars. I tested it on my device which is of smaller width and height.

I placed the cars of with 32 and height 64 according to the camera width, height. It is working fine with my screen size but on larger screen sizes, like the Galaxy Tab, there is a huge space left behind in the game, because cars sizes remain the same as I have to use them in the power of two.

How can I use images that fit all screen sizes? Do I have to use different images according to the image size with different camera width and height? I am sure there is a solution for this.

I already modified my manifest file to support small, large and xlarge sizes.

  public Engine onLoadEngine() {

    final Display display = getWindowManager().getDefaultDisplay();
    CAMERA_WIDTH = display.getWidth();
    CAMERA_HEIGHT = display.getHeight();

    //Toast.makeText(getApplicationContext(), CAMERA_WIDTH, 3);

    mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    engine = new Engine(new EngineOptions(true,
            ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
                    CAMERA_WIDTH, CAMERA_HEIGHT), mCamera).setNeedsMusic(
            true).setNeedsSound(true));

    return engine;
}

解决方案

The thing about using a ratio resolution policy is that you can design your game to a particular size say 800x480 which is very popular for phones these days.

I think where most people stray is thinking they need to pull the current Display width/height and use that to initialize the engine.

The point of a ratio resolution policy - as I understand it - is you set your dimensions to hard coded values and let the ratio resolution policy handle the differences from one device to the next.

CAMERA_WIDTH = 800;
CAMERA_HEIGHT = 480;

//Toast.makeText(getApplicationContext(), CAMERA_WIDTH, 3);

mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
engine = new Engine(new EngineOptions(true,
        ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
                CAMERA_WIDTH, CAMERA_HEIGHT), mCamera).setNeedsMusic(
        true).setNeedsSound(true));

Once you do things like this, then you only need to be sure your graphics and spacing look good at your pre chosen width/height - in this example 800 x 480. If everything works and fits and looks good, then the ratio resolution policy will take care of things when the device has a different screen size.

At least that my take on how it should work - I write for 800 x 480 and everything looks good on my 7" tablet too - granted that's not a major stretch.

这篇关于不同屏幕尺寸和引擎 Android 上的精灵大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆