<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 删除画布中先前绘制的对象

        HTML5 Remove previous drawn object in canvas(HTML5 删除画布中先前绘制的对象)
          • <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 删除画布中先前绘制的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 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>
                      • <tfoot id='Ng3pl'></tfoot>

                      • <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>
                            <tbody id='Ng3pl'></tbody>