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(){
}
}
}
从我可以告诉你的Ball
类是你的draw()
函数中。你可能希望它是外面。事情是这样的:
let ball;
function setup(){
createCanvas(500, 500);
ball = new Ball ();
}
function draw(){
background(0);
}
class Ball{
constructor(){
}
}
需要注意的是正确的缩进可以帮助你发现这样的错误。