此代码不断返回 Ball is not defined
This code keeps returning Ball is not defined
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
class 在 您的 draw()
函数中。你可能希望它在外面。像这样:
let ball;
function setup(){
createCanvas(500, 500);
ball = new Ball ();
}
function draw(){
background(0);
}
class Ball{
constructor(){
}
}
请注意适当的缩进可以帮助您发现这样的错误。
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
class 在 您的 draw()
函数中。你可能希望它在外面。像这样:
let ball;
function setup(){
createCanvas(500, 500);
ball = new Ball ();
}
function draw(){
background(0);
}
class Ball{
constructor(){
}
}
请注意适当的缩进可以帮助您发现这样的错误。