1
Support / [Creating a Customizable 2D Character] Creating Atlases Dynamically at Runtime
« on: June 28, 2014, 02:37:59 am »
Hello, I am trying to create a customizable 2D character that is comprised of 30 different sprites. Assuming that there are 10 variations of each sprite, there would be 300 sprites in total. I also want to have multiple characters on screen at one time. As a result, I am trying to figure out what's the best way to render a given character at runtime if I know the sprite names that need to be shown. There are three solutions:
I want to attempt the last solution. However, I am trying to figure out how to do that with TK2D. I have been reading other threads such as this one: http://2dtoolkit.com/forum/index.php/topic,2576.15.html.
However, I have a few questions about the workflow for this works. From what I gather, it work as follows.
Can you help advise on the workflow above or suggest something else completely if it is not correct.
- Create an atlas for each of the 10 character variations offline. However, this would require me to load all 10 atlases if the character uses a sprite from each character variation. This will waste memory because I am loading a lot of sprites I will never use.
- Create an atlas for each sprite. This would require 30 draw calls per character. If I have 5 characters on screen, that would require 150 draw calls which is too much.
- Since I know which sprites the character will use, I can theoretically create an atlas at runtime and use that. This will require 1 draw call per character.
I want to attempt the last solution. However, I am trying to figure out how to do that with TK2D. I have been reading other threads such as this one: http://2dtoolkit.com/forum/index.php/topic,2576.15.html.
However, I have a few questions about the workflow for this works. From what I gather, it work as follows.
- Use Texture2D.PackTextures to pack the correct textures into an atlas.
- Use tk2dSpriteCollectionData.CreateFromTexture to create a tk2dSpriteCollectionData.
- Use RenderTexture to actually display the character? I'm looked at the Unity documentation for Render Texture and am not sure how it fits into the workflow.
Can you help advise on the workflow above or suggest something else completely if it is not correct.