Search Unity

Rendering multiple sprites with one Object

Discussion in '2D' started by Snowzurfer, Sep 19, 2014.

  1. Snowzurfer

    Snowzurfer

    Joined:
    Sep 19, 2014
    Posts:
    1
    Hey everyone,

    I need to render 2 sprites at the same position, one on top of the other one, using only one GameObject. How can I achieve that?

    I know that I cannot manually render a sprite in Unity2D (if there is a way, please tell me), but I want to do something like (in pseudo code):

    Code (CSharp):
    1. //...enter the drawing section (pseudoCode)
    2. //...
    3.     spriterenderer.draw(spriteOne, x, y, myAlphaValue);
    4.     spriterenderer.draw(spriteTwo, x, y, myAlphaValue);
    5. //...
    This way I could change the alpha value of each sprite individually, so that the one on the top (second one to be rendered) would show part of the first depending on its alpha value, retaining the performance on having just one GameObject.

    Thanks in advance!
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Dynamic batching solves this issue, unless you have several hundred. I suggest you make the game and not worry about premature optimisation which is probably going to make things worse for you.