p5.js - p5.js 库函数不能与 javascript 类函数一起使用?
问题描述
我正在为我的代码使用 p5 库,当我尝试使用库函数创建类函数时,它似乎中断了。我去了参考页面,甚至那里的示例类函数都使用库函数,所以我知道我做错了什么,但我似乎无法弄清楚是什么。
这是我的代码:
class Enemy {
constructor(x, y, radius, health) {
this.x = x
this.y = y
this.health = health
this.r = radius
this.show();
}
// this breaks on strokeWeight();
show() {
strokeWeight(4);
stroke(255, 0, 0);
noFill();
ellipse(this.x, this.y, this.r * 2, this.r * 2;
}
}
这是我得到的错误:
Uncaught ReferenceError: strokeWeight is not defined (sketch: line 11)
它说当我尝试注释掉strokeWeight();
, stroke();
,noFill();
或时每个函数都没有定义ellipse();
。如果你能帮忙,请做。谢谢。
解决方案
我想到了。我需要将类放在类setup()
中对象的初始化之后但之前。
推荐阅读
- powershell - Powershell使用循环一次搜索多个字符串
- java - Java:如何正确访问另一个类的方法 | 里面的示例代码
- java - 使用 LWJGL 调用 vkCmdDraw 会导致本机崩溃
- javascript - 你能找出数据集中的两列是否在同一个位置吗?
- video - 当有两个具有冗余的帧时如何使用冗余发送数据
- mongodb - 如何为mongoDB中的子文档编写具有多个或条件的条件查询
- spring-boot - 如何定期向activemq spring集成DSL发布消息
- msbuild - 如何使用 MSBuild 为 C++/CLI 创建 NuGet 包?
- sql - 如果行数低于一定数量,则在选择结果中插入空行
- django - 比较现有 Django 模型的实例以查找匹配字段?