Hello Guest

Author Topic: How to pick up the pixels of the curent sprite in Atlas(Texture2d)?  (Read 3459 times)

roid100

  • Newbie
  • *
  • Posts: 6
    • View Profile
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

« Last Edit: March 21, 2013, 10:14:25 am by roid100 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile

roid100

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to pick up the pixels of the curent sprite in Atlas(Texture2d)?
« Reply #2 on: March 22, 2013, 02:36:53 am »
That's it!!!
Thank you very much!
You are a super hero!!