live wallpaper background image is bigger than screen size andEngine

338 views Asked by At

I want to use one image for all screen, but if i load bigger image than screen size it is not visible. image size is 1280x720, screen size is 960x540. What can i do?

Code:

public EngineOptions onCreateEngineOptions() {      
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    wm.getDefaultDisplay().getRotation();
    CAMERA_WIDTH = displayMetrics.widthPixels;   
    CAMERA_HEIGHT = displayMetrics.heightPixels;        
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);               
    return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), this.mCamera);}

next:

public void onCreateResources(OnCreateResourcesCallback  createResourcesCallback) throws Exception {        
    final BuildableBitmapTextureAtlas bitmapTextureAtlas = new BuildableBitmapTextureAtlas(
            mEngine.getTextureManager(), CAMERA_WIDTH, CAMERA_HEIGHT,
            TextureOptions.BILINEAR); 
            mTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(bitmapTextureAtlas, this, "gfx/h720x1280a.png");

}

2

There are 2 answers

0
Rama On

Its better to make scale it to support all screens:

int spriteWidth = 1280;
int spriteHeight = 720;
int spriteScaleX = spriteWidth/screenWidth;
int spriteScaleY = spriteHeight/screenHeight;

place this factor as scale to your background sprite.It will support to all devices.

0
Ajay On

You need a image that maintain the ratio of your camera width and height, Its not needed to use large resolution image , OpenGL has the capability to maintain the quality of the image.