Search Unity

Graphics.DrawTexture side effect

Discussion in 'Immediate Mode GUI (IMGUI)' started by NestorArturo, Mar 11, 2010.

  1. NestorArturo

    NestorArturo

    Joined:
    Mar 11, 2010
    Posts:
    4
    Hi... I have this simple script method

    Code (csharp):
    1. void OnGUI()
    2. {
    3.     // Paint the full bar.
    4.     Graphics.DrawTexture(
    5.         fullTarget,
    6.         textureLifeBar,
    7.         fullBar,
    8.         0, 0, 0, 0);
    9. }
    This works as expected: Paints a portion of the texture like a life bar. However is also re-painting it below for what it seems to be the third of its original size. Really don't know why I'm getting this second bar (attached image shows this undesired result, which I'm pretty sure is my bad somehow).

    Every variable is set once in the Star() method, there is nothing inside Update() or FixedUpdate(), no other scripts change this variables... in fact there are no other scripts running.

    Thanks for any help.
     

    Attached Files:

  2. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    254
    You are using Graphics.DrawTexture, try using GUI.DrawTexture and see what happens.
     
  3. NestorArturo

    NestorArturo

    Joined:
    Mar 11, 2010
    Posts:
    4
    Thank you for your tip... I used Graphics.DrawTexture because was very easy to draw a clipped texture with it. Finally, as you suggested, I ended using GUI.DrawTexture which required tripple the lines and more preparation to do the same.

    If someone knows how to fix the issue I'll be back to Graphics.DrawTexture. :D
     
  4. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
  5. NestorArturo

    NestorArturo

    Joined:
    Mar 11, 2010
    Posts:
    4
    Thanks for your reply. I've read that before, but I don't understand what are or how to code Repaint events.
     
  6. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Just a guess:

    Code (csharp):
    1.  
    2. void OnGUI()
    3. {
    4.    if (Event.current.type == EventType.Repaint)
    5.    {
    6.      // Paint the full bar.
    7.      Graphics.DrawTexture(
    8.         fullTarget,
    9.         textureLifeBar,
    10.         fullBar,
    11.         0, 0, 0, 0);
    12.    }
    13. }
    14.  
    15.  
    -Juha
     
  7. NestorArturo

    NestorArturo

    Joined:
    Mar 11, 2010
    Posts:
    4
    Hi and sorry for being this late...

    Thank you JFo for your tip.. it did the magic :D