Author Topic: UISprite, invert X, sprite not visible  (Read 8992 times)

dark_tonic

  • Guest
UISprite, invert X, sprite not visible
« on: September 06, 2012, 10:31:26 AM »
I've had a look through previous posts and done a couple searches and couldn't find this issue.

I have an atlas of sprites created through TexturePacker

I need to make a single sprite face left and face right.

With a basic UISprite, if I set scale x to -1 (or other value) the sprite disappears, so I can't use the flipped version.

I've tried adjusting Z and the UISprite depth function, but it doesn't appear to be a sorting issue.

Other sprites from this same atlas also need to appear in the scene simultaneously.

Thoughts?

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: UISprite, invert X, sprite not visible
« Reply #1 on: September 06, 2012, 11:28:48 AM »
I'm pretty sure that scale <= 0f results in a NaN (not a number) calculation within NGUI.

You could likely code a function to build these mirrored textures at startup time, by just using Texture2D and Get/Set Pixels.  Get them in horizontal or vertical 1-pixel-wide blocks and Set them in the target mirrored texture object.

However, this would mean that the texture is no longer in an atlas, so it wouldn't draw in one call any longer.  You'll likely have to have both versions of the sprite in your atlas.

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: UISprite, invert X, sprite not visible
« Reply #2 on: September 06, 2012, 01:51:26 PM »
I use negative scaling in a bunch of places to mirror sprites, so it's definitely possible.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite, invert X, sprite not visible
« Reply #3 on: September 06, 2012, 02:23:21 PM »
Ditto, I mirror the sprite by specifying a negative scale in Windward in a couple of places, works fine. I generally prefer to rotate it 180 degrees instead though.

The sprite will only disappear with a flipped scale if you're using some shader that does backface culling. NGUI shaders don't, by default.

dark_tonic

  • Guest
Re: UISprite, invert X, sprite not visible
« Reply #4 on: September 06, 2012, 03:55:58 PM »
thanks, everyone!

Yeah, I was using unlit / transparent for the shader.   ::)  I set it to a different transparent shader and it's all working correctly.   ;D


JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: UISprite, invert X, sprite not visible
« Reply #5 on: September 07, 2012, 12:37:57 PM »
Heh.  I am becoming educated one correction of an incorrect assertion at a time!