Before updating to Windows 10 you may need to return your Pro license. More information here

Culling part of a sprite in Sprite Manager 2

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!

more ▼

asked Mar 22, 2011 at 08:38 PM

avatar image

33 6 4 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 28, 2011 at 07:50 PM

avatar image

147 4 3 6

Thanks, I tested both methods and they work really well. It doesn't completely solve the problem, but certainly is much faster and more elegant than the solution I came up with.

I needed this for 2D portals (those from "Portal"). I know that I could settle for depth tricks, but I wanted two sides of the portal to be available to go through, so for example, two object can use each side of one portal simultaneously.

I wrote a shader that cuts off a part of a texture in a material along any axis. I managed to use it and get any rotated sprite work with a portal at any angle, though it's a mess.

Apr 29, 2011 at 08:11 AM mfcas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Mar 22, 2011 at 08:38 PM

Seen: 2932 times

Last Updated: Mar 22, 2011 at 08:38 PM