Search Unity

Question Sprite Efficiency - and Other Sprite Questions

Discussion in '2D' started by jlars789, Aug 9, 2023.

  1. jlars789

    jlars789

    Joined:
    Mar 3, 2023
    Posts:
    16
    I'm currently trying to find a way of applying an animated texture in a general way to entities within my game. For example, when an entity is on fire, I want their sprite (and only their sprite) to have a burning animation.

    My running idea is creating a small burn animation, then squaring them to meet the maximum size of the sprite in any direction, then applying a mask. For example, if my burn animation is 1x1 and my entity is 5x3, I would take 25 (5x5) burn animations, combine them into a single object, then apply the entity as a mask, with the burn animation being over the mask.

    However, I'm wondering how efficient this is, i.e., is there additional overhead on each individual sprite than had I just had a 5x5 burning animation? Is there a way to combine sprites into one to reduce this overhead? I am looking to be as efficient as possible in terms of performance, so any pointers on this would certainly be of assistance.
     
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    if you make many objects and many sprite renderers it will be worse performance than if you had only 1 big sprite

    there some ways to combine sprites like texture2d.setpixels and rendertexture
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    You might have better luck with a few custom-shaped fire particle systems, then just use the closest one to the sprite in question. You could have one for tall, short, wide, narrow, biped, quadruped enemies.

    If you want to use this idea:

    I always find it is a little fiddly... so I keep a sample setup around that I use as a quick reference for how to set stuff up RenderTexture stuff like this.

    See attached package. Try sticking a fire particle system between the "stage camera" and the target thing it is imaging.

    Good luck setting your entities on fire!
     

    Attached Files:

    jlars789 likes this.
  4. jlars789

    jlars789

    Joined:
    Mar 3, 2023
    Posts:
    16
    Thanks for the in-depth reply! I looked a bit into RenderTexture before this and I suppose I didn't understand what it really does - meaning I won't have a good understanding of the package you uploaded here. The example on Unity seemed to be applying a skybox of some kind (but it wasn't exceptionally clear).

    Is the 'Repeat' enum an option that work for my standards? I'm no artist and I'd like to minimize the amount of art (both for time and efficiency sake) and I believe having a minimal burn animation that can be repeated across whatever range, then mapped onto an object - it seems all the necessary tools to do this exist within a SpriteRenderer, I'm just unsure on how to actually implement it in the way I want to, if it is even possible.