Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
153 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...