在V6.0.2中找不到PIXIJS事件系统



我正在PIXIJS v6.0.2中构建一个演示。我正在尝试将点击事件监听器添加到一些按钮中。但这不起作用,所以我查看了文档,在他们的点击事件示例中发现了这段代码。

// In this a example, you can click on a bunny and the more you click at
// a time the bigger it becomes. If you click outside of the bunny or
// lose your clicking speed, the bunny resets.
// Disable interaction plugin (for PixiJS 6)
// eslint-disable-next-line no-underscore-dangle
delete PIXI.Renderer.__plugins.interaction;
// Create app
const app = new PIXI.Application({
antialias: true,
autoDensity: true,
backgroundColor: 0x1099bb,
resolution: devicePixelRatio,
});
document.body.appendChild(app.view);
// Install EventSystem, if not already
// (PixiJS 6 doesn't add it by default)
if (!('events' in app.renderer)) {
app.renderer.addSystem(PIXI.EventSystem, 'events');

但是我得到了这个错误Uncaught TypeError: ClassRef is not a constructor at Renderer.addSystem (core.js:10214) at Module../src/app.js (app.js:22) at __webpack_require__ (bootstrap:19) at main.js:54738 at main.js:54754 at main.js:54941

我正在将PIXIJS导入我的文件中,我正在进行webpack/babel构建。我不确定我遗漏了什么或做错了什么,但我似乎找不到PIXI 6的任何答案。我甚至在PIXI Gitter上都没有得到回应。感谢您的帮助!

事件系统仅在6.1.0+中可用。目前有一个预发布版本6.1.0-rc.2可供使用。

由于某些原因,EventSystem未从pixi.js导出我找到了一个解决方法,分别安装@pixi/events并从中导入事件系统。

// In this a example, you can click on a bunny and the more you click at
// a time the bigger it becomes. If you click outside of the bunny or
// lose your clicking speed, the bunny resets.
import * as PIXI from 'pixi.js';
import { EventSystem } from '@pixi/events';
PIXI.EventSystem = EventSystem;
// Disable interaction plugin (for PixiJS 6)
// eslint-disable-next-line no-underscore-dangle
delete PIXI.Renderer.__plugins.interaction;
// Create app
const app = new PIXI.Application({
antialias: true,
autoDensity: true,
backgroundColor: 0x1099bb,
resolution: devicePixelRatio,
});
document.body.appendChild(app.view);
// Install EventSystem, if not already
// (PixiJS 6 doesn't add it by default)
if (!('events' in app.renderer)) {
app.renderer.addSystem(PIXI.EventSystem, 'events');
...

参考文献:pixi事件

最新更新