Hello, I have no idea how to solve the following problem:
I need to cut off a part of a sprite, so the first half is rendered properly, and the second is not rendered at all (totally translucent). I thought I'd have to do a shader for that but I couldn't really write anything that made sense. I need to adjust how much/what part of a sprite is cut off on the go. By "what part" I mean that I need to be able to not only cut off (for example) right half of the sprite, but also the bottom and along any axis (not really simultaneously).
If you know how to solve this problem (even partially), please post an answer! Many thanks!
There are two ways to do this:
To cut off just one side of a sprite, use one of the Truncate* methods. For example, TruncateRight(0.5f) will truncate the right side of the sprite so that half of it is still showing. TruncateBottom(0.25f) will only leave the top 25% showing (cuts off the bottom).
These methods only cut off one side at a time, however. To cut off multiple sides, use a clipping rect. To do that, decide the rectangular area, in world space, you want to confine the sprite to, and outside of which, the sprite will get cut off. Think of this sort of like framing the sprite.
Create a Rect that describes this rectangular area, we'll assume you call this "clip2D". Then, do this:
Rect3D clip3D = new Rect(clip2D);
Now you can apply the clipping to your sprite:
mySprite.ClippingRect = clip3D;
That's all there is to it.
answered Apr 28 '11 at 07:50 PM