简体   繁体   English

TypeError:在p5.js中使用image()时,无法读取未定义的属性“width”

[英]TypeError: Cannot read property 'width' of undefined when using image() in p5.js

So I'm trying to show an image that I have loaded with loadImage() , but when i get to using the image() function I get 所以我试图显示一个我用loadImage()加载的图像,但是当我开始使用image()函数时,我得到了

TypeError: Cannot read property 'width' of undefined TypeError:无法读取未定义的属性“width”

Here is the code: 这是代码:

let img

function preLoad() {
  font = loadFont('../addons/Fonts/monof55')
  img = loadImage('./yes.jpg')
}

function setup() {
  createCanvas(1200, 600)
  background('darkblue')

  fill('#EEEEEE')
  stroke(25)
  strokeWeight(2)
  rect(0, height - height / 20, width, height / 20)
}

function draw() {
  image(img, 0, 0)
}

Your image isn't loaded, because the function preLoad() is not executed. 您的图像未加载,因为未执行函数preLoad() It has to be preload() instead. 它必须是preload()而不是。 JS is case-sensitive. JS区分大小写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 p5.j​​s 27646:未捕获的类型错误:无法读取未定义的属性“0” - p5.js 27646: Uncaught TypeError: Cannot read property '0' of undefined p5.j​​s上的“未捕获的TypeError:无法读取未定义的属性'bind'” - “Uncaught TypeError: Cannot read property 'bind' of undefined” on p5.js 未捕获的类型错误:无法读取未定义的属性“图像”(p5.js) - Uncaught TypeError: Cannot read property 'image' of undefinded (p5.js) 括号p5.js“未捕获的TypeError:无法读取未定义的属性'offscreen'” - Brackets p5.js “Uncaught TypeError: Cannot read property 'offscreen' of undefined” p5.js web 编辑器。 '未捕获的类型错误:无法读取未定义的属性'拆分'(:第 57 行)' - p5.js web editor. ' Uncaught TypeError: Cannot read property 'split' of undefined (: line 57)' 无法读取函数中未定义的属性“0”(p5.js) - Cannot read property '0' of undefined in a function (p5.js) p5.js 出现错误:未捕获的类型错误:无法读取 null 的属性“transpose3x3” - p5.js getting error: Uncaught TypeError: Cannot read property 'transpose3x3' of null 未捕获的TypeError:无法读取未定义的属性“宽度” - Uncaught TypeError: Cannot read property 'width' of undefined 谁能告诉我为什么我收到错误'无法读取未定义的属性'值''? P5.JS - Can anyone tell me why i am getting the error 'Cannot read property 'value' of undefined'? P5.JS 使用p5.js在JavaScript中未定义JSON属性 - JSON Property undefined in JavaScript with p5.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM