2D Toolkit Forum

2D Toolkit => Support => Topic started by: roid100 on March 21, 2013, 10:12:46 am

Title: How to pick up the pixels of the curent sprite in Atlas(Texture2d)?
Post by: roid100 on March 21, 2013, 10:12:46 am
Hello,

tk2dAnimatedSprite img = GetComponent<tk2dAnimatedSprite>();
Texture2D t = (Texture2D)img.Collection.textures[0];
Color[] cs = t.GetPixels();

in this code,
cs.width is Atlas's width (Pixel).
cs.height is Atlas's height (Pixel).
Isn't it? cs is the data for the whole atlas pixels.

Can I know the Rect data for each sprite?
I mean... there are so many sprites in tk2dAnimatedSprite.
I want to know the color data of each sprites.
something like this...

tk2dAnimatedSprite img = GetComponent<tk2dAnimatedSprite>();
Texture2D t = (Texture2D)img.Collection.textures[0];
Color[] cs = t.GetPixels();
for ( int i = x, i < x + rectWidth; i++ ){
  for ( int j = y, j < y + rectWidth; j++ ){
     print( cs[ y * t.width + x ] );
  }
}

But I don't know how to find rectWidth and rectWidth...
Help me please... T.T

Title: Re: How to pick up the pixels of the curent sprite in Atlas(Texture2d)?
Post by: unikronsoftware on March 21, 2013, 07:15:51 pm
Here is aCallums solution.
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1346.0.html
Title: Re: How to pick up the pixels of the curent sprite in Atlas(Texture2d)?
Post by: roid100 on March 22, 2013, 02:36:53 am
That's it!!!
Thank you very much!
You are a super hero!!