AndEngine camera and Device display : Ratio between co-ordinates on each

ⅰ亾dé卋堺 提交于 2019-12-13 09:36:00

问题


I'm using a FrameLayout on top of Andengine camera to add a button. I need to align the button to a sprite on the andengine camera.

I'm using gravity top in the frame layout and adding top padding to shift the button down. Works while on the development device. But because of the RatioResolutionPolicy, on a different device with different screen size, the alignment does not work.

I am wondering how to find the device screen Display co-ordinates that would exactly coincide with the AndEngine camera co-ordinates. I tried to figure out the ratio and assign the padding but is not working. Can anyone guide me on how to find the co-ordinates on the screen Display that would coincide exactly with the co-ordinates on the AndEngine camera?

Really stuck with this since two days. Any help would be greatly appreciated.

Closest i reached was using this (Button shifts but this is still not exact):

    //get actual screen height of device to find ratio
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int height = size.y;
    int width = size.x;

    //normal ratio logic
    int heigntUsedByCamera = width * CAMERA_HEIGHT / CAMERA_WIDTH;
    int requiredPaddingForBtnOnFrameLayout = (height - heigntUsedByCamera)/2;

In this one I'm expecting the button X to be exactly where the CAMERA starts

What is going wrong here?

OR Is there a better way to add a native button inside the AndEngine Camera?


回答1:


As, it most of the time happens, found the solution myself.

Like i mentioned in my question the code above was getting me close results but not accurate. I figured the deviation was because i had scaled the button to 0.6f. Removed the scaling and it is working perfect.



来源:https://stackoverflow.com/questions/29926903/andengine-camera-and-device-display-ratio-between-co-ordinates-on-each

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!