<small id='UJxrW'></small><noframes id='UJxrW'>

    • <bdo id='UJxrW'></bdo><ul id='UJxrW'></ul>

  • <i id='UJxrW'><tr id='UJxrW'><dt id='UJxrW'><q id='UJxrW'><span id='UJxrW'><b id='UJxrW'><form id='UJxrW'><ins id='UJxrW'></ins><ul id='UJxrW'></ul><sub id='UJxrW'></sub></form><legend id='UJxrW'></legend><bdo id='UJxrW'><pre id='UJxrW'><center id='UJxrW'></center></pre></bdo></b><th id='UJxrW'></th></span></q></dt></tr></i><div id='UJxrW'><tfoot id='UJxrW'></tfoot><dl id='UJxrW'><fieldset id='UJxrW'></fieldset></dl></div>

    <tfoot id='UJxrW'></tfoot>

    <legend id='UJxrW'><style id='UJxrW'><dir id='UJxrW'><q id='UJxrW'></q></dir></style></legend>
      1. HTML5 删除画布中先前绘制的对象

        时间:2023-06-20
          • <bdo id='1nbad'></bdo><ul id='1nbad'></ul>
          • <legend id='1nbad'><style id='1nbad'><dir id='1nbad'><q id='1nbad'></q></dir></style></legend>

            <small id='1nbad'></small><noframes id='1nbad'>

                <tbody id='1nbad'></tbody>

                  <tfoot id='1nbad'></tfoot>
                  <i id='1nbad'><tr id='1nbad'><dt id='1nbad'><q id='1nbad'><span id='1nbad'><b id='1nbad'><form id='1nbad'><ins id='1nbad'></ins><ul id='1nbad'></ul><sub id='1nbad'></sub></form><legend id='1nbad'></legend><bdo id='1nbad'><pre id='1nbad'><center id='1nbad'></center></pre></bdo></b><th id='1nbad'></th></span></q></dt></tr></i><div id='1nbad'><tfoot id='1nbad'></tfoot><dl id='1nbad'><fieldset id='1nbad'></fieldset></dl></div>

                  本文介绍了HTML5 删除画布中先前绘制的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  借助 moveTolineTo 方法,我在 HTML5 画布内绘制了一个多边形对象(比如汽车).我想在画布的不同位置重复绘制该对象(模拟移动对象).我的问题是之前绘制的对象没有被清除.相反,在画布上绘制了多个图像.我该如何解决这个问题?

                  I have a polygon object (say a car) drawn inside a HTML5 canvas with help of methods moveTo and lineTo. I want to repeatedly draw that object at different positions in the canvas (simulating a moving object). My problem is that the previous drawn object is not getting cleared. Instead, multiple images are drawn on the canvas. How can I fix this issue?

                  推荐答案

                  画布只是像素数组,它们对你绘制的形状一无所知.

                  Canvases are just arrays of pixels, they know nothing of the shapes you have drawn.

                  过去在位图显示器上使用了一些动画技巧(例如异或绘图"),可用于在绘制新形状之前移除旧形状,但在现代机器上通常要简单得多(而且速度非常快) 只是擦除画布并为每一帧重新开始.

                  There are animation tricks that used to be used on bitmapped displays (e.g. "xor drawing") that can be used to remove the old shape before you draw the new one, but on modern machines it's generally far simpler (and perfectly fast) to just erase the canvas and start again for each frame.

                  鉴于您对其他答案的评论,我建议只使用两个画布 - 一个用于静态背景,一个用于汽车.如果背景图片是静态的,它甚至可以是 <img> 元素而不是 Canvas.

                  Given your comments to other answers, I'd suggest just using two Canvases - one for the static background and one for the car. If the background image is static it could even be an <img> element instead of a Canvas.

                  如果汽车图像是静态的,您也可以只绘制一次,然后使用 CSS 定位设置其相对于每一帧背景的位置.

                  If the car image is static you could also just draw that once, and then use CSS positioning to set its position relative to the background for each frame.

                  这篇关于HTML5 删除画布中先前绘制的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:画布旋转后查找坐标 下一篇:在 HTML5 画布中绘制鼠标移动的半透明线

                  相关文章

                  1. <small id='Ng3pl'></small><noframes id='Ng3pl'>

                    • <bdo id='Ng3pl'></bdo><ul id='Ng3pl'></ul>
                    <legend id='Ng3pl'><style id='Ng3pl'><dir id='Ng3pl'><q id='Ng3pl'></q></dir></style></legend>
                  2. <tfoot id='Ng3pl'></tfoot>

                  3. <i id='Ng3pl'><tr id='Ng3pl'><dt id='Ng3pl'><q id='Ng3pl'><span id='Ng3pl'><b id='Ng3pl'><form id='Ng3pl'><ins id='Ng3pl'></ins><ul id='Ng3pl'></ul><sub id='Ng3pl'></sub></form><legend id='Ng3pl'></legend><bdo id='Ng3pl'><pre id='Ng3pl'><center id='Ng3pl'></center></pre></bdo></b><th id='Ng3pl'></th></span></q></dt></tr></i><div id='Ng3pl'><tfoot id='Ng3pl'></tfoot><dl id='Ng3pl'><fieldset id='Ng3pl'></fieldset></dl></div>