Author Topic: Collision areas of buttons not precise in different mobile resolutions  (Read 6001 times)

Brastik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Hello,
I've just started using NGUI and found it super cool with design UIs. However I just got some weird issues today and had no idea what exactly could cause the problem.
My game's images are designed for 1200x800px resolution and in UIRoot script of my UI I set Scaling Style "FixedSizeOnMobiles", Manual Height "1200", Minimum Height "1200". And there is no problem when I run the game in Unity simulator, the issue occurred when the game played on an android device with resolution 480x320px.
(See attached screenshot please)
I got two buttons at the bottom of the screen (the ninja pic and the shuriken one).
It looked like the collider boxes of these two buttons were "moved" a bit toward center of the stage, or what I thought was due to NGUI auto scaling stuff (not really sure since I already tested with 480x320px resolution in Unity simulator with no problems found).
Anyone already had same problem, or have some ideas on this please?
Sorry if I didn't make it clear enough and thanks for any suggestions!
Cheers.

Abnaxus

  • Guest
Did you attach the box collider dynamically (by setting a position and size) or did you use NGUI->AttachCollider on your sprite ?

If it's the first one, you might want to check your positions, because from one resolution to another, positions slightly change.

Your box collider should also be centered in (0,0) and sized to (1,1) if you want collision detection on your full sprite.

Dunno if it helps, just answer back. :)

Brastik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Hi there,
Thanks for the suggestions. The buttons are Simple Button widgets so they have box colliders added by default. I also set the position for their colliders to (0,0), and size to full sprite. I found one thing weird to notice was that the problem only occurred on mobile devices (I've also tested on 800x480px resolution and found same problem), there's no issues found on different resolutions of simulator.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Make sure your panel isn't marked as "static". The note about centering the box collider isn't quite right. It's only correct if the sprite is centered as well. In all cases, Alt+Shift+C is the shortcut that updates the collider's dimensions after resizing / positioning the sprite.

Brastik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
No my panel isn't marked "static" (as by default it isn't, I think).
I've tried to create a new UI, created 2 Button widgets and moved them to left and right corner like the first screenshot then still seen the same problem like I've described.
One thing I noticed about the Button widgets was when I created one, its background's scale would (always) be a fixed value (150,40) as well as its attached collider's size. Anyone got same thing happened? Or is that on purpose?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
A button is:

Button GameObject (collider)
- Background (sprite)
- Label (text)

Button game object has a scale of (1, 1, 1). Collider has a scale that sums up the contents dimensions, and since the background sprite starts with a scale of 150, 40, that's what you will see reflected on the collider as well.

Brastik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
But, what I mean is, that scale (150,40) seems to apply to any button I create with Widget Tool > Template 'Button', even if I choose a background that is not 150x40, that's why I thought (150,40) was something on purpose or default or something like that.
It'd be ok if I then manually set the collider and sprite (background) scale to its actually size but this is happening everytime I create a widget button in any panel of any UI. Maybe there's something wrong being set in my project, anyway still hope someone already had and solved the similar issues. 

Brastik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Ok I think I've solved the collision problem with buttons. I created a new project, use the same images, etc. and the problem's gone. I found out the thing caused that problem was another UI I put in the hierarchy besides my main UI, so I thought there should be only one UI in hierarchy before the game run, or anyone had any ideas why's that?
Anyway was super happy I got it working, tyvm for any suggestions guys  ;D

Abnaxus

  • Guest
Why would you need 2 UI ?  ???