Alguem pode me ajudar com esse erro no p5js.org ?
To fazendo o código, mas fica aparecendo esse erro e eu não consegui resolver
p5.js says: [carros.js, line 10] image() was expecting Number for the second parameter, received an empty variable instead. If not intentional, this is often a problem with scope.
- More info: https://p5js.org/examples/data-variable-scope.html (http://p5js.org/reference/#/p5/image)
p5.js says: [carros.js, line 11] image() was expecting Number for the second parameter, received an empty variable instead. If not intentional, this is often a problem with scope.
- More info: https://p5js.org/examples/data-variable-scope.html (http://p5js.org/reference/#/p5/image)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/addons/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<main>
</main>
<script src="game.js"></script>
<script src="images.js"></script>
<script src="ator.js"></script>
<script src="carros.js"></script>
</body>
</html>
style.css
html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
images.js
let ImagemDaEstrada;
let ImagemDoAtor;
let ImagemCarro1;
let ImagemCarro2;
let ImagemCarro3;
function preload() {
ImagemDaEstrada = loadImage("images/estrada.png")
ImagemDoAtor = loadImage ("images/ator-1.png")
imagemCarro = loadImage ("images/carro-1.png")
imagemCarro2 = loadImage ("images/carro-2.png")
imagemCarro3 = loadImage ("images/carro-3.png")
}
sketch.js
function setup() {
createCanvas(500, 400);
}
function draw() {
background(ImagemDaEstrada);
MostraAtor();
MovimentaAtor();
mostraCarro();
MovimentaCarros();
VoltaCarros();
}
Ator.js
//Ator
xAtor = 170;
yAtor = 370;
function MostraAtor() {
image(ImagemDoAtor, xAtor, yAtor, 25, 25);
}
function MovimentaAtor(){
if (keyIsDown(UP_ARROW)){
yAtor -=3;
}
if (keyIsDown(DOWN_ARROW)){
yAtor = yAtor +3;
}
}
carro.js
//código do carro
let yCarros = [40, 95, 150];
let xCarros = [600, 600, 600];
let velocidadeCarros = [3, 2.5, 3.5];
function mostraCarro(){
image(imagemCarro, xCarros[0], yCarros[0], 50, 40);
image(imagemCarro2, xCarros[1], yCarros[1], 50, 40);
image(imagemCarro3, xCarros[2], yCarros[2], 50, 40);
}
function MovimentaCarros() {
xCarros -= velocidadeCarros[0];
xCarros -= velocidadeCarros[1];
xCarros -= velocidadeCarros[2];
}
function VoltaCarros (){
if (xCarros[0] < -50){
xCarros[0] = 600;
}
if (xCarros[1] < -50){
xCarros[1] = 600;
}
if (xCarros[2] < -50){
xCarro[2] = 600;
}
}