11

` 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;
}
sheraz amin
  • 1,149
  • 2
  • 14
  • 23

3 Answers3

14

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.

jmroyalty
  • 2,527
  • 1
  • 17
  • 21
  • I tested a high resolution background for the game scene (1240x840) with camera 800x480, the background looks clipped. So I do not understand how it works fine for you!!!!!! – Ashraf Sayied-Ahmad Apr 04 '13 at 16:04
  • so turn it around - write for the higher resolution using a camera of 1240x840 and let AndEngine deal with the smaller devices. As I said, I write for 800x480 but my tablet is only 1280x800 – jmroyalty Apr 09 '13 at 19:33
  • As per my view, use camera with 1024x600 resolution. It work good with small and high resolution device. – Siddharth Apr 12 '13 at 17:35
  • Ratio resolution policy is nice, although I find it not very helpful when developing a pixel-art based game in which you usually want to match the size of the pixels of the art with the one of the display. Ratio resolution policy tends to resize in non-integer sizes which leads to maginification / minification artifacts. – thalador May 31 '13 at 08:05
  • What is the best height and width for portrait mode? – rasen58 Aug 23 '13 at 00:10
  • +1 to the answer. You can also use different resolution policies, because Ratio RP has few drawbacks. Check my article with illustrations: http://android.kul.is/2013/10/andengine-tutorial-dealing-with-screen-sizes.html – MartinTeeVarga Oct 28 '13 at 03:57
3

Fetch the height of the device and width and then algebraically make the sprite a percentage of the screen width and height.

Hope that helps.

user1432813
  • 162
  • 2
  • 10
0

According to my experience, I think that the best way to attack this issue is to deal with two major screen ratios (5:4, 5:3) which are popular in most of the devices.

You choose a high resolution for each ratio and let the engine scale down if the device screen size is smaller.

Ashraf Sayied-Ahmad
  • 1,715
  • 2
  • 18
  • 21