- Home /
Question by
PhyrePhrost · Aug 09, 2021 at 12:21 PM ·
animationspriterendererspriterendererfill
Creating a fill animation for sprite renderer
Hi, i want to recreate a fill animation (like that used into Image) for the Sprite Renderer, i've create this one, but if i call it every frame (or every time a value change) it create lags into the game
static Sprite Function(/*passed values*/)
{
for (int x = 0; x < sprite.texture.width; x++)
{
for (int y = 0; y < sprite.texture.height; y++)
{
float div = (float)x / width;
Color m_color;
if(div <= percentage01)
{
m_color = sprite.texture.GetPixel(x, y).a == 0 ?
newTexture.GetPixel(x, y) :
sprite.texture.GetPixel(x, y);
}
else
{
return newTexture;
}
newTexture.SetPixel(x, y, m_color);
}
}
newTexture.Apply();
Rect rect = new Rect(0, 0, newTexture.width, newTexture.height);
var m_finalSprite = Sprite.Create(newTexture, rect, new Vector2(0.5f, 0.5f), sprite.pixelsPerUnit, 0, SpriteMeshType.FullRect);
m_finalSprite.name = spriteName;
return m_finalSprite;
}
can you help me to make the animation smooth and without lags?
Comment
Your answer
Follow this Question
Related Questions
Force a SpriteRenderer to render at a position different from the actual transform's position 0 Answers
Sprite on SpriteRenderer not keyframing? 1 Answer
How change sprite animation texture?? 2 Answers
How to animate a sprite mask? 0 Answers
Moving from Renderer to SpriteRenderer causes Lag on Mobile 0 Answers