p5.js 中的错误:"pushMatrix() not used, see push()"

Error in p5.js: "pushMatrix() not used, see push()"

每次我 运行 我的代码,它都会给我一个错误:

p5.js says: An error with message "pushMatrix() not used, see push()" occured inside the p5js library when pushMatrix was called (on line 175 in sketch.js [/sketch.js:175:13])

If not stated otherwise, it might be an issue with the arguments passed to pushMatrix. (http://p5js.org/reference/#/p5/pushMatrix)

但是,pushMatrix() 在我的代码中不存在。 当我尝试通过将 push() 替换为 pushMatrix() 来修复它时,它给了我同样的错误:

p5.js says: An error with message "pushMatrix() not used, see push()" occured inside the p5js library when pushMatrix was called (on line 175 in sketch.js [/sketch.js:175:13])

If not stated otherwise, it might be an issue with the arguments passed to pushMatrix. (http://p5js.org/reference/#/p5/pushMatrix)

我的代码:https://pastebin.com/gMxwvJLA(Whosebug 不让我 post 这个问题,因为代码太大)

简而言之:pushMatrix() 不是 p5 中的有效函数。它不存在。您想要查找 pushMatrix() 的所有用法并将其替换为 push() and popMatrix() with pop().

通过这些替换,您的代码运行没有任何错误,我看到一个正方形在 canvas 的中心旋转。

错误消息不是特别有用,但查看 the source code 可以澄清很多事情。

/**
 * @for p5
 * @requires core
 * These are functions that are part of the Processing API but are not part of
 * the p5.js API. In some cases they have a new name, in others, they are
 * removed completely. Not all unsupported Processing functions are listed here
 * but we try to include ones that a user coming from Processing might likely
 * call.
 */

import p5 from './main';

p5.prototype.pushStyle = function() {
  throw new Error('pushStyle() not used, see push()');
};

p5.prototype.popStyle = function() {
  throw new Error('popStyle() not used, see pop()');
};

p5.prototype.popMatrix = function() {
  throw new Error('popMatrix() not used, see pop()');
};

p5.prototype.pushMatrix = function() {
  throw new Error('pushMatrix() not used, see push()');
};

export default p5;