画布清除问题。选择在Canvasteroids中不清除的对象

编程入门 行业动态 更新时间:2024-10-17 04:45:51
本文介绍了画布清除问题。选择在Canvasteroids中不清除的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用html5画布创建了一个新的小行星游戏。它已经到了很高的地步,我必须动态地将激光器在舞台上。他们不正确绘制(它们应该只有10像素长),当你拍摄两次,相隔10秒钟旧的激光轨迹显示。这是网址,因为有更多的代码,而不是我关心让每个人都通过。

I am creating a new asteroids game with html5 canvas. It's been going well up to the point where I have to dynamically draw lasers onto the stage. They don't draw correctly (they should only be 10pixels long) and when you shoot twice over 10 seconds apart the old laser trail shows up. Here's the url because there's more code than I care to put everyone through.

marccannon/canvasteroids/

理想情况下,激光器将是10px长,一旦他们失去生命就离开(1秒或33帧)。它们从一个数组中得到 shift(),该数组不应该在绘制循环中运行它们。它似乎有一些类型的内存与激光对象类。到目前为止,我花了几个小时制作空间艺术与激光步道,而不是添加实际的小行星打。有人请帮忙。

Ideally the lasers will be 10px long and go away once they're out of life (1sec or 33 frames). They get shift() out of an array that should no longer be running them in the draw loop. It seems as though there's some kind of memory with the Laser object class. So far I've spent hours making space art with laser trails instead of adding the actual asteroids to hit. Someone please help. I'm losing my sanity.

推荐答案

问题是,当你画在画布上,你必须总是记得调用 beginPath(),否则所有 moveTo 和 lineTo 命令将继续添加和添加到当前路径。

The problem is that when you draw on a canvas you must must always remember to call beginPath(), otherwise all moveTo and lineTo commands will keep adding and adding to the current path.

更多推荐

画布清除问题。选择在Canvasteroids中不清除的对象

本文发布于:2023-11-23 19:06:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:画布   中不   对象   Canvasteroids

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!