Author Topic: full screen transparent button  (Read 6647 times)

duncanx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
full screen transparent button
« on: February 10, 2014, 11:10:49 AM »
I needed a way to detect that the user touched the background (camera based app) so I used a UISprite, pushed it back into the z, stretched it to the screen size and set the color alpha to 0, collider, messager, etc. Works. On mobile are there any performance concerns of having a fullscreen transparent sprite? Or, is it actually not redrawing the screen since it's completely invisible?

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: full screen transparent button
« Reply #1 on: February 10, 2014, 11:24:09 AM »
Use directly an UIWidget with collider to detect a touch.

I think that Michael just disable the sprite rendering with its alpha is 0, there is no reason to draw the sprite. But don't do that !!!

Transparency is a pain on mobile where it is fillrate limited ... having a transparency sprite on the entire screen is a crime against humanity !
Graphicstream Dev.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: full screen transparent button
« Reply #2 on: February 10, 2014, 05:14:26 PM »
ALT+SHIFT+W adds an invisible sprite (also right click, add an invisible widget). ALT+SHIFT+C adds a collider to it. Resize it / position it as you need it. Adjust its depth so that it's in front or behind certain things.

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: full screen transparent button
« Reply #3 on: February 10, 2014, 10:07:50 PM »
Yes, NGUI in one of the most recent updates got some functionality changed where when a sprite's alpha is 0 it gets handled as if it wasn't there in a way (as in it doesn't get rendered), so a sprite with alpha 0 and collider and some button script on it would not get the button press script executed.
You could make it still trigger by setting the alpha to something very low like 1 (instead of 0) but as Cripple said correctly, doing a fullscreen size button with alpha 1 is just no good idea resource usage wise.

I did something like a fullscreen transparent button in following way:
-Create a gameobject and put a UIWidget and a Box Collider on it
-For the UIWidget's Anchors i set it to unified, set the target to the root gameobject of my UI and set the left to target's left, right to target's right etc (and offset value always set to 0) so that way the widget gets stretched to the full screen size
-then in the widget's inspector also set auto adjust to match for the Box Collider.
-then add a script which does something when you press it (i'd guess disable this game object and do something else)

This is kinda handy since placing a fullscreen collider makes it easy to not have events passed to your stuff behind the ui when not wanted and if you have some code somewhere else checking for mouse/finger ray position or similar you can check there if no collider on ui layer was hit, too =)