Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: miyudreams on September 10, 2013, 09:30:49 PM
-
Hi,
I have a drag panel in the middle of the screen. I want to calculate the height of the drag panel.
What I have is a TOP Anchor component in a GameObject set to relative offset y = -0.474
The drag panel is a child of this Anchor GameObject.
I have also placed a toolbar of buttons at the bottom of the screen.
Hence, the height of the drag panel is between the top anchor and the bottom toolbar.
Calculation: (using Samsung Galaxy S3 = 720x1280)
TopToAnchorPixels = Screen.height * anchorY = ie: 1280 * -0.474 * -1.0f = 606.72
AnchorToBottomPixels = Screen.height - TopToAnchorPixels = 1280 - 606.72 = 673.28
BottomToolbarHeightPixels = Stretch Y * Screen.height = 0.095 * 1280 = 121.6
So height of drag panel:
DragPanelHeight = AnchorToBottomPixels - BottomToolbarHeightPixels = 673.28 - 121.6 = 551.68
UIPanel panel = this.gamesDragPanel.GetComponent<UIPanel>();
Vector4 clipRange = panel.clipRange;
clipRange.x = 0.0f;
clipRange.y = -clipCenter; // minus from the top anchor
clipRange.z = Constants.SCREEN_WIDTH * panelXPercent;
clipRange.w = DragPanelHeight ;
panel.clipRange = clipRange;
This calculation sets the drag panel clip box correctly for 480x800 (HTC), 600x1004 (kindle fire), iPhone 4 (480x960), but for some reason it doesn't work for Samsung Galaxy S3 (720x1280).
The drag panel is way too big. I can set the height to something smaller, and the drag panel will fit perfectly (without overlapping the toolbar). But I'm afraid this issue happens on other resolutions or devices. So dynamically calculating it is a much safer bet.
Any ideas? Is there something special I need to do for Samsung?
The bad image looks like this:
(http://db.tt/1RGOOFPq)
This is how it should look, with the drag panel items NOT overlapping the toolbar.
(http://db.tt/HaDNjwfa)
-
Help! This is very puzzling to me. Has anyone seen this problem? Is it only Samsung Galaxy S3?
Thank you
-
1280x720 is a different aspect ratio from 800x480. You need to take that into consideration. You are only considering height.