简体   繁体   English

C#,XNA箭头应仅在矩形中可见

[英]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 目前,我的矩形如下所示: Rectangle

But it should look like this: Rectangle 但它应该看起来像这样: 矩形

Two solutions: 两种解决方案:

  1. Draw all to RenderTarget2D , and then draw it to game window. 全部绘制到RenderTarget2D ,然后将其绘制到游戏窗口。

  2. Use Clipping (for XNA 4 ) 使用剪辑 (对于XNA 4

Fisrt way will be better if you want move result image with all renderet on it. 如果要移动所有渲染图都在其上的结果图像,Fisrt方式会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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