Author Topic: Zooming  (Read 10444 times)

sluresylta

  • Guest
Re: Zooming
« Reply #15 on: October 15, 2012, 06:13:13 AM »
Ok, great - so that's probably what's causing my problem, then.

I was bumbling about a bit when setting this up, since I couldn't find any examples, tutorials or whatnot that covered what I wanted to do: Drag the entire panel by click-dragging anywhere on the panel. Ie. drag the whole board around, regardless of what was on it.

So, what's the correct way of achieving this, then? Where does the collider need to go if I can't have it on the panel? Does every sprite in the panel need one, with UIDragPanelContents attached? If so, will that affect performance in any noticeable way if there are 500-2000 sprites in the panel (about 10 unique sprite types, small, all using the same atlas)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Zooming
« Reply #16 on: October 15, 2012, 06:21:01 AM »
Collider usually goes on the sprite that serves as the background for the panel. That's the collider that should also get a UIDragPanelContents. All that script does is forwards drag events to the draggable panel script.

sluresylta

  • Guest
Re: Zooming
« Reply #17 on: October 15, 2012, 07:43:02 AM »
Ah, ok - that makes sense :-)

So - considering that the sprites/board squares I already have in that panel completely cover the panel - would it be feasible to use a 1-pixel, stretched graphic as background to save atlas space?

sluresylta

  • Guest
Re: Zooming
« Reply #18 on: October 15, 2012, 10:17:31 AM »
I have now changed things up, so that my hierarchy is as follows:

Root
->Camera
-->Anchor
--->Panel
---->Empty game object/sprite holder
----->Background sprite

I've attached a box collider and UIDragPanelContents to the background sprite.

The board is draggable, but regrettably I'm seeing the exact same behavior as I had before. So I guess that was a blind alley. Anything else that could cause this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Zooming
« Reply #19 on: October 15, 2012, 01:25:22 PM »
It doesn't need to be a sprite. It can just be an empty object. The advantage of it being a sprite is that NGUI menu -> Add Collider will automatically resize the collider to the sprite's dimensions. With an empty game object you need to resize it yourself.

sluresylta

  • Guest
Re: Zooming
« Reply #20 on: October 20, 2012, 12:18:37 PM »
Ok, I removed the sprite - I don't want unnecessary objects floating about - and moved the collider and the UIDragPanelContents script to the empty object instead. After juggling the event handlers etc. around, I got the panel draggable and everything else working. Except for my original problem: the panel's edges would still be dragged way into the game window/viewport.

After much headscratching, observation and a couple of semi-qualified guesses, though, I managed to figure it out and work out a solution. I have no idea if it's an ideal solution, but it seems to work well. Here goes:

While I was looking at the Scene view while dragging the panel around in the Game view, I noticed that what was restricting how far I could drag the edges was the pink rectangle indicating the clip range. Not the edge of the viewport, as I had previously assumed.

When I zoomed out by doubling the camera's orthographic size, the camera of course rendered not only what was going on inside the clip range, but also all that was going on outside it. Which was basically just a black nothing.

So, in order to make my zooming work properly, I had to do a couple of extra steps. Namely resize the clip range so it would cover the same size of area as the camera frustum (is that the correct term for orthographic camera's?), and slide the panel's anchor over to have the clip range precisely overlay the frustum.

I hope this helps someone down the line.
« Last Edit: October 21, 2012, 06:51:32 AM by sluresylta »