Search Unity

Representing damage on sprites

Discussion in '2D' started by smalldragon979, Dec 22, 2013.

  1. smalldragon979

    smalldragon979

    Joined:
    Nov 13, 2011
    Posts:
    33
    Hello, I'm making a game using unity's 2D tools, in this game there are blocks that are damageable, in order to represent a block's damage I would like parts of the sprite to become transparent (showing the background behind it) whenever it is damaged (like if it was breaking apart), what would be the best and most efficient way to accomplish this using unity's built in sprites?
     
  2. jospor

    jospor

    Joined:
    Oct 23, 2013
    Posts:
    10
    First thing that comes into my mind is modifying the texture in the renderer to remove a certain pattern of pixels for every stage of damage.
     
  3. smalldragon979

    smalldragon979

    Joined:
    Nov 13, 2011
    Posts:
    33
    I though about doing that, but I think that modifying a texture at runtime is too recourse intensive. At least that was my experience last time I played around with generating a texture at runtime, even though the textures I'm using have a much lower resolution, I'm afraid that doing that might cause some lag spikes later on when multiple blocks have to be damaged at the same time, but I might be wrong.
     
  4. jospor

    jospor

    Joined:
    Oct 23, 2013
    Posts:
    10
    You could create a script to process imported textures into several different textures with damage changes. Not very good if you have large file sizes but it would work.
     
  5. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Personally, I would put all the textures representing the damaged blocks in a single atlas (together with the other textures as well) and change them on-the-fly, just make some 2 or 3 variations and they won't look all the same. It's just an idea though... Possibly it will look better also; man-made art for a damaged block can't be beaten by removing random pixels. :)
     
  6. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    Do this. ;) It's much more efficient to swap sprites than modify them directly during runtime.
     
unityunity