Author Topic: I'm making a custom filled sprite, some questions about the drawingDimensions  (Read 425 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
I'm extending the UISprite to make a progress-bar like the Dota2's HP-bar.

What I've done is to make a subclass of UISprite and override the OnFill method:
1. It can set the tiling numbers, like: I want one green-block for 100 hp, so 1200hp will need to be 12-tiles.
2. Each tile-block is sliced;

This picture is what I've made for now.

The problem is, that there's a extra green line at the 50% position.

After some digging in the code, I've found that it's from UISprite.drawingDimensions,
  1.                         float vx = Mathf.Lerp(x0, x1 - fw, mDrawRegion.x);
  2.                         float vy = Mathf.Lerp(y0, y1 - fh, mDrawRegion.y);
  3.                         float vz = Mathf.Lerp(x0 + fw, x1, mDrawRegion.z);
  4.                         float vw = Mathf.Lerp(y0 + fh, y1, mDrawRegion.w);

I cannot really grasp why the vz is from x0 + fw to x1.
Assume I set the fillAmount to 0.5 with UISlider, and with this fomula, if the source sprite data has borders, I'm going to get the result image to go past the mid point, like in the picture below.

(This is what an original UISprite looks like when fillAmount = 0.5, you can see it go past the mid point obviously)

Is it an expected behaviour or a bug?


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,151
  • Toronto, Canada
    • View Profile
I'm not sure what you're not understanding there. It goes up to the half point with the 50% position. x0 + fw to x1 Means it will go from the point where the previous slice ended up to the end (x1). Check the size of your sprite you'r etrying to tile. Make sure its dimensions are dividable by two.