1

How to set Sprite size for all device? i am using this for sprite :

    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());

but when i run game on devices with smaller screen, the sprite size remains same. How to overcome this?

raj
  • 2,088
  • 14
  • 23
  • If you are using RatioResolutionPolicy then you don't have to bother about this. – Siddharth Jun 04 '13 at 17:22
  • m using this 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); – raj Jun 06 '13 at 04:32
  • If you want to achieve same result on all devices then use CAMERA_WIDTH and CAMERA_HEIGHT as you developed graphics from your designer such as 800x480 or 1024x600. – Siddharth Jun 06 '13 at 16:08

3 Answers3

0

Try using the "dp" unit on your sprite size. if you're using "px" it will not scale on other devices.

Please read this link for more details :)

Community
  • 1
  • 1
reidzeibel
  • 1,622
  • 1
  • 19
  • 24
  • px and py is the location not size – raj Jun 03 '13 at 06:06
  • 1
    You misunderstood my explanation :)), I mean, you have to set the image density, maybe using setDensity() or something like that. in that size setting, use "dp" instead of "px". of course I know that `pX` and `pY` is the position of your sprite – reidzeibel Jun 03 '13 at 06:20
0

The answer give by @Siddharth in the comment is correct. In AndEngine, you are not supposed to scale Sprites to fit screen sizes yourself. Instead you should use built-in AndEngine functionality to scale the whole scene accordingly.

@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);
}

Now when you set CAMERA_WIDTH and CAMERA_HEIGHT, to 1280x720 and your Sprite size is 640x360, AndEngine will scale the whole scene up or down including your Sprite on any screen to 1280x720. Your Sprite will always take one quarter of the screen.

MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
0

Replace

 new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT)

with this

new FillResolutionPolicy()

with FillResolutionPolicy you only need work in one dimension and it automatically this resize for all devices

Vinicius DSL
  • 1,839
  • 1
  • 18
  • 26