画布清除问题。选择在Canvasteroids中不清除的对象 [英] Canvas clearing issue. Select objects not clearing in Canvasteroids

查看:378
本文介绍了画布清除问题。选择在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.

http://marccannon.com/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中不清除的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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