好吧,我只想尝试将此字体添加到我的网站,但此错误会一直显示在控制台中。
Uncaught TypeError: Cannot read property 'length' of undefined
at Substitution.getDefaultScriptName (p5.js:31993)
at Font.stringToGlyphs (p5.js:27954)
at Font.forEachGlyph (p5.js:28069)
at Font.getAdvanceWidth (p5.js:28144)
at p5.Font._textWidth (p5.js:63498)
at p5.Font._handleAlignment (p5.js:63523)
at p5.Font._getPath (p5.js:63339)
at p5.Font._renderPath (p5.js:63458)
at p5.Renderer2D._renderText (p5.js:48828)
at p5.Renderer2D.text (p5.js:48788)
这是唯一出现的错误,它会使我的整个代码停止。
这是我的代码:
var sound;
var imgs = [];
var myFont;
function preload() {
soundFormats('mp3');
sound = loadSound('Your Reality.mp3');
myFont = loadFont('assets/monika.ttf');
for (var i = 0; i < 12; i++) {
imgs[i] = loadImage('assest/img(' + i + ').png');
}
}
function setup() {
imageMode(CENTER);
sound.setVolume(0.5);
sound.play();
//sound.onended(soundEnd);
createCanvas(windowWidth-20, windowHeight-20);
text("Click Anywhere!", 0, 10);
soundEnd();
}
function soundEnd() {
imgs = [];
for (var i = 0; i < 12; i++) {
imgs[i] = loadImage('assets/img(' + i + ').png');
}
reload();
textSize(36);
textFont(myFont);
var inter = setInterval(flashText, 200);
}
function flashText() {
text("Just Monika", floor(random(0, width-30)), floor(random(0, height-15)));
}
function windowResized() {
resizeCanvas(windowWidth - 20, windowHeight - 20);
}
function reload() {
resizeCanvas(windowWidth - 20, windowHeight - 20);
text("Click Anywhere!", 0, 10);
}
应该发生的是音乐播放,您可以点击鼠标(此代码中不包含鼠标点击功能,因为它是无关紧要的)并且会出现一些图像,在音乐结束后会出现一组不同的图像,然后是文本&#34; Just Monika&#34;应该以特定字体在屏幕上闪烁,但字体不起作用,这是p5.js的问题吗?