Search Unity

Sprite clipping

Discussion in '2D' started by sshepelevich, Nov 21, 2013.

  1. sshepelevich

    sshepelevich

    Joined:
    Nov 21, 2013
    Posts:
    10
    Hello,

    I want to implement health bar. I have custom texture for it. My idea was to draw it as a sprite and show it partially. In 2DTK I'd use tk2dClippedSprite for such functionality. Is it possible to do using Unity's Sprite?
     
  2. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    Yes. take a look at 2D example project in the asset store and watch

    There are a healthBar implemented. Him explain exactly how to do it. And there is a script inside the project that you can use it in your own project.
     
  3. sshepelevich

    sshepelevich

    Joined:
    Nov 21, 2013
    Posts:
    10
    This is not really what I need. Example project just resizes tinted sprite. What I need is to clip my health bar texture is not simple and I cannot just stretch it depending on player's health.
     
  4. Stephen-Zhou

    Stephen-Zhou

    Joined:
    Sep 23, 2013
    Posts:
    4
    You can use 9 sprites to realize SlicedSprite, so 3 sprites can make up a 3-slicedsprite. I mean, we have to write a class ourselves.
     
  5. sshepelevich

    sshepelevich

    Joined:
    Nov 21, 2013
    Posts:
    10
    Well, using 9 sprites instead of 1 just to simulate clipping is too overhead, but thanks for suggestion!