let ball;
// declared
function setup(){
createCanvas(500, 500);
ball = new Ball ();
// this is the problem keeps saying ball is not defined
// i have defined it
// can anyone point out the mistake
}
function draw(){
background(0);
class Ball{
constructor(){
}
}
}
答案 0 :(得分:3)
据我所知,您的Ball
类在您的draw()
函数的内部 内。您可能希望它在外面。像这样:
let ball;
function setup(){
createCanvas(500, 500);
ball = new Ball ();
}
function draw(){
background(0);
}
class Ball{
constructor(){
}
}
请注意,适当的缩进可以帮助您发现这样的错误。