多个画布元素如何影响性能? [英] How multiple canvas elements affect performance?

查看:92
本文介绍了多个画布元素如何影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在画布上制作一个简单的游戏(从上方看)。请告诉我,这是更快的方法:

I'm trying to make a simple game (view from above) on canvas. Please tell me, which is faster:

1)在一个< canvas> 上绘制所有内容并计算面积

1) Draw everything on one <canvas> and calculate the areas that need to be redrawn.

2)在不同的< canvas> 元素上绘制场景的某些部分,然后仅在必要时更新每个。在it变体中,也许我也可以使用部分重绘。

2) Draw certain parts of the scene on different <canvas> elements and update each only if necessary. In the it variant, probably, I can also use a partial redraw.

例如,我可以在一个元素上绘制地图,在第二个元素上绘制敌人,并使用光标等第三。当移动敌人时,我只能重画第二张画布。

For example, I could draw a map on one element, enemies on the second, and a cursor and etc on the third. When moving enemies, I could only redraw the second canvas.

请尽可能详细地说明哪个选项更好,为什么。而且,您能否建议能加深我对此问题知识的书籍?对于初学者。

Please explain in as much detail as possible which option is better and why. And could you please advise books that can deepen my knowledge on this issue? For beginners.

推荐答案

大多数画布游戏都会使用您所描述的一种分层。最远的前一层将是HUD,由单独的画布或HTML元素组成,并且只有在发生某些事情(例如有人升级播放器)时,HUD才会改变。然后,这取决于他们如何绘制画布。最简单的方法是简单地绘制地图的各个部分,并且障碍物在屏幕上。

Most canvas games will use a sort of layering that you are describing. The furthest forward layer would be the HUD, either by a seperate canvas or HTML elements and this would only change if something happened to it, such as someone upgrading their player. Then after that it depends on how they draw the canvas. The simplest way would be to simply draw the portions of the map and obstacles are on the screen.

这篇关于多个画布元素如何影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆