Всем привет. Можете мне помочь? Я хочу что бы при зажатии квадрат двигался но не получается вот код:
function startAll() {
let canv = document.getElementById("canvas")
let ctx = canv.getContext("2d");
canv.width = window.innerWidth;
canv.height = window.innerHeight;
//создаём квадрат
let x1 = window.innerWidth / 2;
let y1 = 0;
let speed = 1;
let move = false;
function kyb(x, y, w, h) {
ctx.fillstyle = "black";
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
ctx.fillRect(x, y, w, h);
}
let play = function () {
move = true;
if (move === true) {
console.log(move);
kyb(x1, y1, 50, 50);
y1 += speed;
}
if (y1 > window.innerHeight) {
y1 = 0;
}
}
let stop = function () {
move = false;
}
canv.addEventListener("touchstart", play);
canv.addEventListener("touchend", stop);
}
startAll срабатывает при полной загрузке страницы