I know is hard to understand but, here's the code
function aleatorizar() {
const random = Math.random() * canvas.width;
return random;
}
function desenharbombas(x) {
ctx.beginPath();
ctx.arc(x, posição, 50, 0, 2 * Math.PI);
ctx.stroke();
ctx.fillStyle = "#000000";
ctx.fill();
function escrever() {
ctx.font = "17px Arial Black";
ctx.fillStyle = "#ffffff";
ctx.fillText("texto", x, posição);
}
escrever()
}
function animar() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
desenharbombas()
requestAnimationFrame(animar);
//como passar parametro da função animar para o parametro da função desenhar bombas
}
animar()
So, as you can see, in the "desenharbombas" function, i need the parameter to determine where my "bombs" will be located in the x axis, and that number is randomized by the "aleatorizar" function, so i need a solution where i can put a parameter on the function "animar", (which would be the randomized number function), and pass it to the "desenhar bombas function". representing it, it would be something like this (this doesn't work btw)
function desenharbombas(x) {
//x parameter defines the x axis of the bombs, and i need this number to be randomized
ctx.beginPath();
ctx.arc(x, posição, 50, 0, 2 * Math.PI);
ctx.stroke();
ctx.fillStyle = "#000000";
ctx.fill();
function escrever() {
ctx.font = "17px Arial Black";
ctx.fillStyle = "#ffffff";
ctx.fillText("texto", x, posição);
}
escrever()
}
function animar(y) {
//that's where the problems at, this solution doesn't work, i need to use a parameter to
another parameter in the "desenharbombas"
function
ctx.clearRect(0, 0, canvas.width, canvas.height);
desenharbombas(x = y)
requestAnimationFrame(animar);
//como passar parametro da função animar para o parametro da função desenhar bombas
}
animar(y = aleatorizar())
//this is the parameter i need to recieve to use in the "desenharbombas" function
For the love of god, i've been stuck on this for hours, please be my savior