Author Topic: Button at the same position on the screen when zooming a camera  (Read 2929 times)

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Hi,

I'm trying to create  a button in the bottom left of the screen which will remain the same size regardless of the screen/camera size. I have a 2D camera which can be zoomed into a sprite, so what I'd like is to have a 'Reset Map' button appear and remain on the screen as soon as the zoom/camera size is less than 1. I'm currently trying this with a separate viewport setup with a second camera (as in example 8 in the NGUI example scenes) and the button appears in the correct place through the main 2D camera. However, it seems to be shrinking in size as I zoom in.

The setup I have is;

> View UI (with UI Root, UIPanel)
  > Anchor (UIAnchor with main 2D camera as the UI Camera and set to Center, None for container)
    > Offset (UIAnchor with View camera as UI Camera, set to Bottom-Left, None for container)
      > Button (with Unified anchor with Target as View UI, Left/Right set to: Left, Top/Bottom set to: Bottom)

Any ideas on how I keep the size of this constant?
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button at the same position on the screen when zooming a camera
« Reply #1 on: July 31, 2014, 11:37:58 AM »
UIAnchor was deprecated a long time ago and should not be used. NGUI has a powerful layout system that you should be using instead. Look at the Example 1 that comes with NGUI and try zooming in there by changing the camera's orthographic size. The buttons will get smaller or bigger as you do so, but you can change their anchors to be using relative values instead of absolute, which will make them use precentage-based values, so they will then maintain the same size proportionally to their target's dimensions.