在不同的屏幕尺寸Andengine的Andr​​oid雪碧大小 [英] Sprite size on different screen size Andengine Android

查看:141
本文介绍了在不同的屏幕尺寸Andengine的Andr​​oid雪碧大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

`我正在开发Android中Adnengine我的第一场比赛。这是一个从顶视图的赛车游戏。我用视差背景和一些车。我在我的设备是较小的宽度和高度上进行了测试。

余放置的汽车32和高度64根据照相机的宽度,高度。这是工作的罚款与我的屏幕尺寸,但是,更大的屏幕尺寸,像Galaxy Tab的,有在游戏中留下了巨大的空间,因为汽车的尺寸保持不变,因为我必须使用他们两人的力量。

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

我已经修改了我的清单文件,以支持小,大,XLARGE大小。

 公共引擎onLoadEngine(){

    最终显示显示= getWindowManager()getDefaultDisplay()。
    CAMERA_WIDTH = display.getWidth();
    CAMERA_HEIGHT = display.getHeight();

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

    mCamera =新照相机(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
    发动机=新引擎(新EngineOptions(真,
            ScreenOrientation.LANDSCAPE,新RatioResolutionPolicy(
                    CAMERA_WIDTH,CAMERA_HEIGHT),mCamera).setNeedsMusic(
            真).setNeedsSound(真));

    返回引擎;
}
 

解决方案

有关使用比例分辨率政策的事情是,你可以设计你的游戏到一个特定的大小说800×480,这是非常受欢迎的手机,这些天。

我想大多数人流浪在思考他们需要拉的当前显示宽度/高度,并用它来初始化引擎。

的比例分辨率政策的要点 - 我的理解 - 是你设定的尺寸硬codeD值,让比解决政策处理从一个设备的差异下

  CAMERA_WIDTH = 800;
CAMERA_HEIGHT = 480;

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

mCamera =新照相机(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
发动机=新引擎(新EngineOptions(真,
        ScreenOrientation.LANDSCAPE,新RatioResolutionPolicy(
                CAMERA_WIDTH,CAMERA_HEIGHT),mCamera).setNeedsMusic(
        真).setNeedsSound(真));
 

一旦你做这样的事情,那么你只需要确保你的图形和间距看好在你的pre选择宽度/高度 - 在此例中为800 x 480。如果一切正常,并配合和看起来不错,那么比解决策略会照顾的事情时,该设备具有不同的屏幕尺寸。

至少,我拿上它应该如何工作 - 我为800×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.

这篇关于在不同的屏幕尺寸Andengine的Andr​​oid雪碧大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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