简体   繁体   English

PIXIJS eventSystem 在 V6.0.2 中找不到

[英]PIXIJS eventSystem is not found in V6.0.2

I am building a demo in PIXIJS v6.0.2.我正在 PIXIJS v6.0.2 中构建一个演示。 I am trying to add on click event listeners to some buttons.我正在尝试将单击事件侦听器添加到某些按钮。 But that doesn't work, so I went into the documentation and found this snipped of code in their example of a click event.但这不起作用,所以我进入文档并在他们的点击事件示例中发现了这段代码。

// 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');

But I get this error 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但我收到此错误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

I am importing PIXIJS into my file I am doing a webpack/babel build.我正在将 PIXIJS 导入到我的文件中,我正在执行 webpack/babel 构建。 I'm not sure what I'm missing or doing wrong but I cannot seem to find any answers to this for PIXI 6. I don't even get a response on the PIXI Gitter.我不确定我错过了什么或做错了什么,但我似乎无法为 PIXI 6 找到任何答案。我什至在 PIXI Gitter 上都没有得到回应。 Any help is appreciated thank you!感谢您提供任何帮助!

The events system is only available in 6.1.0+.事件系统仅在 6.1.0+ 中可用。 Currently there is a prerelease 6.1.0-rc.2 you can use.目前有一个可以使用的预发行版 6.1.0-rc.2。

For some reason EventSystem is not being exported from pixi.js I found a workaround by installing @pixi/events separately and import the Event System from there.由于某种原因 EventSystem 没有从 pixi.js 导出,我找到了一种解决方法,方法是单独安装@pixi/events并从那里导入 Event System。

// 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');

...

References: pixi events参考: pixi 事件

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM