Hello Guest

Author Topic: Getting AnimatedSprite's textures  (Read 4473 times)

Pulluxx

  • Newbie
  • *
  • Posts: 9
    • View Profile
Getting AnimatedSprite's textures
« on: May 20, 2013, 04:39:48 pm »
Hey!  :)

I want to be able to modify the hue and saturation of an animated sprite during runtime. I've looked around a bit, and found a HSV color-struct which will help me out with this. This code works for a Texture2D:

Code: [Select]
void SetSaturation(float saturation)
{

  texture2D = animSpriteTexture;

Color[] pixels = texture2D.GetPixels();

for (int i = 0; i < pixels.Length; i++)
{

HSVColor temp = HSVColor.FromColor(pixels[i]);
temp.s = saturation;
pixels[i] = temp.ToColor();
}

texture2D.SetPixels(pixels);
texture2D.Apply ();
}

So what I'd like to do is to either:

1. Have a script (which probably inherits from tk2dAnimatedSprite) that for every frame can get the current frame's Texture2D at runtime and then run this function.

2. Perhaps get the GameObject's atlas and apply the changes to the whole atlas.

How would I go about this? I want to be able to only modify one GameObjects saturation this way (and let all other GameObjects which have the same AnimLib have their own saturation), so I'm wondering, GameObjects which share the same AnimLib, do they have an unique atlas for their animations or do they all share one?
« Last Edit: May 20, 2013, 04:48:53 pm by Pulluxx »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Getting AnimatedSprite's textures
« Reply #1 on: May 20, 2013, 06:12:25 pm »
Problems with doing this:
1. There is no "Texture2D" for the current frame. The sprites are atlased, meaning the current frame is simply pulled in from a much larger image. The source sprites don't exist at runtime.
2. Changing texture contents like this is really really slow, and adds a massive memory overhead - both in runtime & storage.
3. Everything just exists in one big atlas, so the problem will be that if you change one sprite it will change all copies. Again, you can work around this by creating duplicates but that increases memory overhead further.

If you really need to do this (depending on platform), it might be worth looking into a shader solution.

Pulluxx

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Getting AnimatedSprite's textures
« Reply #2 on: May 21, 2013, 10:04:47 am »
Thanks for your information. I was a bit afraid that it might be that way. Well, I'll see if I can achieve it with shaders.