I’m working on a rather simple Animation2D class that’ll let me cycle through textures or frames on a material. I’ll be using it as the basis of a 2D sprite-based game.
My question is whether it would be more efficient to use Material.SetTextureOffset() or Material.SetTexture() to cycle through my frames. The former would use a spritesheet and would have a list of indexes to cycle through, while the latter would have a list of textures to cycle through. While I’m thinking the former is more efficient, it’s not as easy to use in the editor. You’d have to provide for image size, frame columns/rows, etc. as well as follow some sort of chart for setting the indexes. With the latter, you just drag your individual frame textures into the list in the inspector, which would be great for my artist friend to be able to easily build his own sprites and get them to me in a package or whatever.
animatedMaterial.SetTexture("_MainTex", textures[currentIndex]);
// or
animatedMaterial.SetTextureOffset("_MainTex", frames[currentIndex]);
A smaller and less important question:
Which would be better, using Update and Time.deltaTime or FixedUpdate and Time.fixedDeltaTime to measure the time between frames? Time between frames is a float currently set through a fps variable in the editor.
timeSinceLastFrame += Time.fixedDeltaTime;
// or
timeSinceLastFrame += Time.deltaTime;
if (timeSinceLastFrame >= timeBetweenFrames)
//...
[Third small question found myself, will omit]
Thanks!