简体   繁体   English

绘制带有fps且没有fps的多个矩形

[英]draw multiple rectangles without fps drop with framegraphics

I'm trying to draw some rectangles on my panel and then make them fall down but because of my program needs to redraw the background and every rectangle everytime it loops the fps is dropping alot when I add alot of rectangles. 我试图在面板上绘制一些矩形,然后使其掉落,但是由于我的程序需要重绘背景,因此每次循环时,当我添加很多矩形时,fps都会掉落很多矩形。

this is my code to draw all the rectangles: 这是我绘制所有矩形的代码:

frameGraphics.FillRectangles(Red, rectlist.ToArray());

Is there anyother way to make this faster? 还有其他方法可以使速度更快吗? since the rectlist.toarray() contains around 400-500 rectangles. 因为rectlist.toarray()包含大约400-500个矩形。


I'm using winforms: 我正在使用winforms:

        Graphics g = Canvas.CreateGraphics(); where canvas is my panel.
        Bitmap frame = new Bitmap(Game.CANVAS_WIDTH, Game.CANVAS_HEIGHT);
        Graphics frameGraphics = Graphics.FromImage(frame);

this is how I build up my graphics. 这就是我建立图形的方式。

Winform is using Gdi+ which lockes a lot during its real drawing. Winform使用的Gdi +在实际绘制过程中会锁定很多东西。 So it limits the drawing speed. 因此,它限制了绘制速度。 I think there are several options for you. 我认为有几种选择适合您。

  1. Use XNA + Winform. 使用XNA + Winform。 You can check this article for detial. 您可以检查这篇文章的详细信息。 This gives little enhancements. 这几乎没有增强。 http://www.dreamincode.net/forums/topic/338422-xna-and-winforms/ https://gamedev.stackexchange.com/questions/54998/winform-xna-microsoft-example-issues-with-drawing-texture2d http://www.dreamincode.net/forums/topic/338422-xna-and-winforms/ https://gamedev.stackexchange.com/questions/54998/winform-xna-microsoft-example-issues-with-drawing-的Texture2D

  2. Try other toolkits like SlimX or Direct3D which will be faster than Gdi+. 尝试使用其他工具包,例如SlimX或Direct3D,它们会比Gdi +快。

  3. Strongly recommend you to use Wpf, you can create shapes and dynamically change their positions, so that you don't need to take care of the render part. 强烈建议您使用Wpf,可以创建形状并动态更改其位置,因此您无需照顾渲染部分。

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

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