I am using p5.js and I am getting the error: "loadAnimation is not defined and createSprite not defined." (same happening in VSCode)
I am using p5.js and I am getting the error: "loadAnimation is not defined and createSprite not defined." (same happening in VSCode)
var bg, sleep, brush, gym, eat, drink, move, astronaut;
function preload()
{
bg = loadImage("images/iss.png");
sleep = loadAnimation("images/sleep.png");
brush = loadAnimation("images/brush.png");
gym = loadAnimation("images/gym1.png","images/gym1.png","images/gym2.png","images/gym12.png");
eat = loadAnimation("images/eat1.png", "images/eat2.png");
drink = loadAnimation("images/drink1.png", "images/drink2.");
move = loadAnimation("images/move.png", "images/move1.png");
}
function setup()
{
createCanvas(400, 400);
astronaut = createSprite(300, 200);
astronaut.addAnimation("sleeping", sleep);
astronaut.scale = 0.3;
}
function draw()
{
background(bg);
drawSprites();
}
我不得不尝试重新输入它并检查我正在加载的文件。它似乎仍然没有工作或做任何事情。
link 到文件:https://editor.p5js.org/tyagihersh/sketches/Vw6exQaUr
将您的 index.html 更改为
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/addons/p5.sound.min.js"></script>
<script src="p5.play.js"></script>
<script src="p5.dom.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
结果应该是这样的
有关更多信息,请查看 p5 中的示例项目
https://editor.p5js.org/ebenjmuse/sketches/BJ4fQ9WxG
var bg, sleep, brush, gym, eat, drink, move, astronaut;
function preload()
{
bg = loadImage("images/iss.png");
sleep = loadAnimation("images/sleep.png");
brush = loadAnimation("images/brush.png");
gym = loadAnimation("images/gym1.png","images/gym1.png","images/gym2.png","images/gym12.png");
eat = loadAnimation("images/eat1.png", "images/eat2.png");
drink = loadAnimation("images/drink1.png", "images/drink2.");
move = loadAnimation("images/move.png", "images/move1.png");
}
function setup()
{
createCanvas(400, 400);
astronaut = createSprite(300, 200);
astronaut.addAnimation("sleeping", sleep);
astronaut.scale = 0.3;
}
function draw()
{
background(bg);
drawSprites();
}
我不得不尝试重新输入它并检查我正在加载的文件。它似乎仍然没有工作或做任何事情。
link 到文件:https://editor.p5js.org/tyagihersh/sketches/Vw6exQaUr
将您的 index.html 更改为
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/addons/p5.sound.min.js"></script>
<script src="p5.play.js"></script>
<script src="p5.dom.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
结果应该是这样的
有关更多信息,请查看 p5 中的示例项目 https://editor.p5js.org/ebenjmuse/sketches/BJ4fQ9WxG