Sé que es difícil de entender, pero aquí está el código.
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()Entonces, como puede ver, en la función "desenharbombas", necesito el parámetro para determinar dónde se ubicarán mis "bombas" en el eje x, y ese número es aleatorio por la función "aleatorizar", entonces necesito una solución donde puedo ponerle un parámetro a la función "animar", (que sería la función de números aleatorios), y pasarlo a la función "desenhar bombas". representándolo, sería algo como esto (esto no funciona por cierto)
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" functionPor el amor de Dios, he estado atascado en esto durante horas, por favor sé mi salvador
Creo que algo como esto funcionaría:
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(randomNumber) { ctx.clearRect(0, 0, canvas.width, canvas.height); desenharbombas(randomNumber) requestAnimationFrame(animar); //como passar parametro da função animar para o parametro da função desenhar bombas } const randomNumber = aleatorizar(); animar(randomNumber)function aleatorizar() { const random = Math.random() * canvas.width; return random; } function desenharbombas(aleatorizar) { //call the function using function_name() and then assign it to a variable x = aleatorizar() 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); //pass the function as a parameter desenharbombas(aleatorizar) requestAnimationFrame(animar); } animar()Déjame saber si esto es lo que estabas tratando de hacer