Author Topic: UISprite - copy a few pixels into another UISprite  (Read 4917 times)

camelord

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
UISprite - copy a few pixels into another UISprite
« on: April 17, 2014, 10:26:53 AM »
hi,

i thought it would get easy but it won't!
I have a UISprite (Sprite A) showing a Sprite from an atlas. The sprite is the background of my scene.
Above this UISprite (meaning higher Depth) is a another UISprite (Sprite B), that is has about 10 pixel width but grows in height when running the scene.
At the corner of the scene there is a third UISprite (Sprite C).

All i want to do now is to copy a row of pixels of Sprite A to Sprite C where the growing Sprite B marks the line of pixels:

Line of pixels is an Array of Pixels (colors) with a width of 10 pixels (X-direction) and a height of 2 Pixels (Y-direction).
The Position where the Pixels have to be readed from are marked by the bottom corner of the growing Sprite B:

Attached is a quick painted image of the scenario..

i hope you can help me.

camelord

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite - copy a few pixels into another UISprite
« Reply #1 on: April 17, 2014, 01:15:22 PM »
Why would you do this? You should never modify the atlas texture by yourself. This is just plain wrong. Use a UITexture to draw a custom texture. Don't mess with the atlas.

camelord

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UISprite - copy a few pixels into another UISprite
« Reply #2 on: April 17, 2014, 01:21:33 PM »
I just need the pixel Infos from Sprite A..  Sprite C can also be any other Object, that fits better to draw the read pixels

- Update -

i tried to create a Texture like this as a simple test:

1. I added a plain GameObject to the scene
2. I assigned SpriteRenderer Script
3. I assigned a little custom script, that i call from Update() function of another gameobject (i assigned this new gameobject to the other one
and access the function via getComponent<T>() call.)

void drawColors ()
{
   Debug.Log ("drawColors()");
   Texture2D newTex = new Texture2D(500,500, TextureFormat.ARGB32, false);
      
   for(int x = 200; x < 300; x++)
      for(int y = 200; y < 300; y++)
         newTex.SetPixel(x,y,Color.green);

   newTex.Apply();
   renderer.material.mainTexture = newTex;
}

Nothing happens! What do i wrong?
« Last Edit: April 17, 2014, 01:59:18 PM by camelord »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite - copy a few pixels into another UISprite
« Reply #3 on: April 18, 2014, 02:05:20 PM »
Widgets have no renderer. Panels create draw calls by taking the widget's material and making a copy of it, creating one or more objects that do have a renderer. Like I said if you need to modify a texture at run time, use a UITexture to draw it. Don't modify an atlas.