How to clip part of the Image
by Altaf · in Torque Game Builder · 11/22/2009 (11:34 am) · 10 replies
Hello,
I have an object of class t2dStaticSprite. Size is 100 x 100 ( in pixels). I want to be able to clip part of the image at run time. How do I do that? I have seen lot of people have already posted this question, but there were no solutions.
thanks in advance.
I have an object of class t2dStaticSprite. Size is 100 x 100 ( in pixels). I want to be able to clip part of the image at run time. How do I do that? I have seen lot of people have already posted this question, but there were no solutions.
thanks in advance.
#2
What I want is,
I want to implement a health bar. I have two images one in Red & the other in white. These images have same dimensions. What I intend to do is, If the health decrease clip upper part of the Red image by 10 pixels(say). This show the decrease in health. I also have other images which have the same requirements. I know TGE, TGEA very well but new to TGB. Can I achieve this with what you have suggested?
11/23/2009 (7:41 am)
Thanks for the reply.What I want is,
I want to implement a health bar. I have two images one in Red & the other in white. These images have same dimensions. What I intend to do is, If the health decrease clip upper part of the Red image by 10 pixels(say). This show the decrease in health. I also have other images which have the same requirements. I know TGE, TGEA very well but new to TGB. Can I achieve this with what you have suggested?
#3
11/23/2009 (12:14 pm)
Thanks... Got it working. As you said... I created a new class & modified the renderObject function...
#4
11/23/2009 (2:06 pm)
I had found a solution in the forums for a progress bar previously by simply setting the width of the object on top. Not sure where that is at any more but it didn't require changing any existing functions, just creating a new behavior.
#5
I would be better if TGB takes care of it by a function call.
11/23/2009 (2:32 pm)
I got it to clip. But now I have another problem. After clipping the image is getting scaled to fit the Size. I dont know why such a basic feature is not implemented by the engine. I used it in TGE & TGEA for GUI.I would be better if TGB takes care of it by a function call.
#6
Also, Drethon's method works if you are just using solid red/white bars. Just put the solid white bar underneath and red, and scale the red based upon your percentage.
11/23/2009 (3:12 pm)
You probably need to set the UV texture coordinates to be proportional to the percentage you want.Also, Drethon's method works if you are just using solid red/white bars. Just put the solid white bar underneath and red, and scale the red based upon your percentage.
#7
11/23/2009 (3:15 pm)
My images are circular in shape. So scaling wont help me. I did change the texture co-ordinates. For testing purpose, I have set the MinY = 0.5f. What ends up happening is, rest of the texture is scaled up to fit the image size :(
#8
11/23/2009 (3:47 pm)
Finally... Got it working. Thanks guys
#9
11/23/2009 (3:59 pm)
Cool! Great to hear!
#10
11/23/2009 (4:16 pm)
Wups, did not think of non rectangular objects, will note that for the future in case I have to use something like this...
Associate William Lee Sims
Machine Code Games
If you want arbitrary clipping, you'll have to modify (or copy) the t2dStaticSprite and modify the class to take a clip region (polygon?) and modify the renderObject function. This is very easy if you have even the most basic OpenGL knowledge.