Hello everyone, today I want to show you what I’ve been working on the past few days, to celebrate my 100 stars(thank you:roll_eyes:) on the SpriteSheetRenderer repo on GitHub.
With this system, you can render a huge amount of animated sprites at very high FPS(1 million animated sprites at 60fps)
C# 4 required
I created 3 demos where you will find a simple tutorial on how to bulk/single instantiate and also a fractal visualization.
In this update, I rewrote the API to make it super easy to instantiate sprites
public Sprite[] sprites;
public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem) {
// 1) Create Archetype
EntityArchetype archetype = eManager.CreateArchetype(
typeof(Position2D),
typeof(Rotation2D),
typeof(Scale),
//required params
typeof(SpriteIndex),
typeof(SpriteSheetAnimation),
typeof(SpriteSheetMaterial),
typeof(SpriteSheetColor),
typeof(SpriteMatrix),
typeof(BufferHook)
);
// 2) Record and bake this spritesheet(only once)
SpriteSheetManager.RecordSpriteSheet(sprites, "emoji");
int maxSprites = SpriteSheetCache.GetLength("emoji");
var color = UnityEngine.Random.ColorHSV(.35f, .85f);
// 3) Populate components
List<IComponentData> components = new List<IComponentData> {
new Position2D { Value = float2.zero },
new Scale { Value = 15 },
new SpriteIndex { Value = UnityEngine.Random.Range(0, maxSprites) },
new SpriteSheetAnimation { maxSprites = maxSprites, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 },
new SpriteSheetColor { color = new float4(color.r, color.g, color.b, color.a) }
};
// 4) Instantiate the entity
Entity e = SpriteSheetManager.Instantiate(archetype, components, "emoji");
}
Update an entity:
SpriteSheetManager.UpdateEntity(e, new Position2D { Value = float2.zero });
Destroy an entity:
SpriteSheetManager.DestroyEntity(e, "emoji");
To get some insight on how I made this system, you can check this post
Let me know what do you think about this and feel free to use it inside your game/prototype