清晰的html5问题
我有这个代码
function clear(){
context2D.clearRect(0, 0, canvas.width, canvas.height);
}
function desenhaBonecoDir(){
clear();
context2D.setTransform(1, 0.30, 1, -0.30, 10, 380);//problem here
context2D.drawImage(bonecoRight, x, y);
x += -10 * xDirection;
}
如果我删除评论“此处问题”的行,则脚本运行良好,但如果我用设置的变换改变视角,我不知道为什么,图像被复制但未删除,结果是当我按下按键时重复图像
有帮助吗?
谢谢
i have this code
function clear(){
context2D.clearRect(0, 0, canvas.width, canvas.height);
}
function desenhaBonecoDir(){
clear();
context2D.setTransform(1, 0.30, 1, -0.30, 10, 380);//problem here
context2D.drawImage(bonecoRight, x, y);
x += -10 * xDirection;
}
if i delete the line where i comment "problem here", the script works well, but if i change the perspective with the set transform i don't know why, the image is copied but undeleted,the result is a repeated image when i press the keys
Any help?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题是由于更改视角引起的,但在清除视角时却没有将其改回来,因此它清除了“视角”而不是整个画布,请尝试下面的操作。它的作用是保存当前的视角,然后将其更改为您需要的任何内容,绘制等,然后恢复恢复以前的视角,以便您恢复正常的坐标。
稍微修改一下你的代码以显示它的工作原理。
http://jsfiddle.net/89yjG/1/
评论保存并恢复,您会注意到的文物。
The problem is caused from changing the perspective, but not changing it back when you clear it, so it clears the "perspective" and not the whole canvas, try below. What it does is saves the current perspective, you then change it to whatever you need, draw etc, then restore restores the previous perspective so you get your normal coords back.
Modified your code just a bit to show it working.
http://jsfiddle.net/89yjG/1/
Comment save, and restore and you'll notice the artifacts.