Sprite size on different screen size Andengine Android

前端 未结 3 1438
轮回少年
轮回少年 2020-12-05 08:14

` 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 sm

相关标签:
3条回答
  • 2020-12-05 09:05

    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.

    0 讨论(0)
  • 2020-12-05 09:08

    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.

    0 讨论(0)
  • 2020-12-05 09:14

    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.

    0 讨论(0)
提交回复
热议问题