绘制圆与绘制位图
我计划在我的游戏中实现一组新的图形:普通圆圈。绘制的精灵(在本例中为圆形)的数量从 2-3 开始,并且可以无限增加(可能)。不过,最多可能会在 60 左右。总共必须有 5 种类型的圆圈,每种圆圈都有不同的颜色和可能的大小。现在看来我要到周一才会实现它,我想我应该在 stackoverflow 上询问它。
有人知道哪种方法更快吗?
I'm planning on implementing a new set of figures in my game: plain circles. The number of drawn sprites (in this case circles) starts with 2-3, and can go up endlessly (potentially). The maximum will probably be around 60 though. In total there will have to be 5 types of circles, each with a different color and probably size too. Now seeing as I won't implement it until monday I thought I'd ask it at stackoverflow.
Does anybody already know which method is faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
位图几乎总是比任何类型的绘制都快。通过正确的准备,绘制位图只是将内存转储到屏幕上。绘制圆涉及大量计算,包括抗锯齿。我在 JavaOne 2009 上发表了一篇论文,其中涵盖了这一点,但旧的论文似乎已从该站点删除。
它确实取决于您的位图需要有多大,但对于 10 像素以下的尺寸,位图精灵甚至比绘制十字和线条等简单的图形操作要快得多。您还需要确保您的精灵在绘制时不需要任何类型的转换,并且它是与屏幕内存兼容的形式。
如果每个圆圈的颜色或厚度不同,或者更糟糕的是大小不同,那就是另一回事了。创建每个位图的成本将超过节省的成本。
您还应该记住优化的第一条规则:除非必要,否则不要这样做。
Bitmaps are almost always faster than any kind of draw. With the right preparation drawing a bitmap is simply dumping memory to the screen. Drawing a circle involves a significant number of calculations, including anti-aliasing. I presented a paper which covered this at JavaOne 2009, but papers that old seem to have been removed from the site.
It does depend on how big your bitmap would need to be, but for sizes under 10 pixels bitmap sprites are much faster than even simple graphic operations like drawing crosses and lines. You also need to make sure that your sprite won't require any kind of transform when it is drawn, and that it is a form compatible with the screen memory.
If every circle is to be a different color or thickness, or worse a different size, then that's another matter. The cost of creating each bitmap would outweigh the savings.
You should also remember the first rule of optimization: don't do it unless you have to.