简体   繁体   中英

C#, XNA Arrows should only be visible in a rectangle

I created a red rectangle with yellow arrows in it. The arrows are always moving upwards and every arrow has the same speed. If an arrow is out of the rectangle(crosses the upper edge of the rectangle), then a new arrow should enter the rectangle at it's bottom. In addition, the rectangle can slowly move upwards and downwards.

How can I draw the rectangle so that just the parts of the arrows are visible that are in the rectangle?

For the moment, my rectangle looks like this: Rectangle

But it should look like this: Rectangle

Two solutions:

  1. Draw all to RenderTarget2D , and then draw it to game window.

  2. Use Clipping (for XNA 4 )

Fisrt way will be better if you want move result image with all renderet on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM