javascript - p5.js 声音:如何使用 removeCue() 删除单个提示
问题描述
p5.js 声音库文档说 removeCue() 可用于取消提示事件。它说它需要一个从 addCue() 返回的 ID 输入。
当我调用 addCue 并将结果存储到变量时,它不会返回 ID。它返回 NaN。
下图是我使用 p5.js 代码编辑器编写的代码示例。
我如何获得身份证?
解决方案
好的,我发现了问题。
这是库https://github.com/processing/p5.js/blob/master/lib/addons/p5.sound.js的问题
看看这个链接https://github.com/processing/p5.js/blob/master/lib/addons/p5.sound.js#L2178
它的使用var id = this._cueIDCounter++;
但从_cueIDCounter
未被定义。
所以我尝试为您的代码定义如下:
Object.defineProperty(mySound,'_cueIDCounter',{value:1,writable:true});
现在它返回了 id。
所以然后我尝试删除提示,removeCue
但令我惊讶的是还有一个问题正在出错Uncaught TypeError: Cannot read property 'splice' of undefined
所以然后我再次查看了库代码,我在下面的行https://github.com/processing/p5.js/blob/master/lib/addons/p5.sound.js#L2198中的 removeCue 函数中意识到是一个错误当前代码是
p5.SoundFile.prototype.removeCue = function (id) {
var cueLength = this._cues.length;
for (var i = 0; i < cueLength; i++) {
var cue = this._cues[i];
if (cue.id === id) {
this.cues.splice(i, 1);
}
}
if (this._cues.length === 0) {
}
};
但它应该使用this._cues.splice(i, 1);
而不是this.cues.splice(i, 1);
推荐阅读
- php - 如何在codeigniter的单行中显示相同的id数据?
- android - 如何跟踪我的应用程序的 ActivityManager 加载时间?
- java - 使用 Retrofit 和 PHP 作为后端,无法从 android 中的服务器接收任何响应
- spring-boot - 带有 CompletableFuture 的 Spring Boot 异步调用,异常处理
- c++ - 将对象向量插入对象向量集时出错
- css - 如何删除这些卡之间的高度
- python - 如何使用python在具有匹配_id的MongoDB表中插入一个新字段?
- python - 在嵌套字典中查找键
- wordpress - 我们如何根据 wordpress 中选择的旅馆下拉列表中的值下载文件
- kubernetes - 为什么k8s服务被删除了,但是集群IP还在