问题描述
我想通过javascript创建突破游戏。我想知道为什么ctx.clearRect无法正常工作。我想将矩形放在y坐标430中以使其显示在画布的底部。当我使用window.setInterval时,它会移动。但是矩形不断移动。 任何帮助,将不胜感激。对不起,我英语不好。
var canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');
var position = 0;
var yposition = 430;
var length = 80;
var width = 20;
var xSpeed = length*1;
var ySpeed = 0;
function R(){
ctx.fillStyle = "green";
ctx.fillRect(position,yposition,length,width);
};
function C(){
position += xSpeed;
yposition += ySpeed;
};
window.setInterval(() => {
ctx.clearRect(0,430,width);
R();
C();
},150);
ctx.beginPath();
ctx.arc(150,50,20,Math.PI * 2,true);
ctx.closePath();
ctx.fillStyle = "blue";
ctx.fill();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)