使用P5js,我尝试将本地文本文件中的文本元素放入数组中。pets.txt在新的行上包含了猫狗。
希望这段代码能解释这个问题。感谢您的关注!
var pets;
var petArray = [];
function preload() {
.
.
.
pets = loadStrings("pets.txt");
petArray = pets.splitText(',');
}
function draw() {
.
.
.
fill(0);
textSize(20);
text(pets,60,height-10); //prints... cat,dog
text("X" + petArray[1],160,height-10); //prints... Xundefined
}发布于 2021-02-27 01:43:11
看起来‘宠物’已经是一个数组了--所以不需要petArray = pets.splitText(',');
我不知道为什么上面的方法不起作用,但我已经解决了将文本文件放入数组的问题。
https://stackoverflow.com/questions/66383004
复制相似问题