目前,试图让Pixi.js 6运行角度为12(但11似乎也面临同样的问题)。
如果我尝试用pixi初始化一个带有画布的组件,并添加一个sprite,那么我确实遇到了Pixi如何将它的基类初始化的问题。
错误TypeError:无法读取未定义的BatchSystem.setObjectRenderer (BatchSystem.ts:56)的属性“start”
import { AfterViewInit, Component, ElementRef, NgZone } from "@angular/core";
import { Application } from "@pixi/app";
import { Sprite } from "@pixi/sprite";
@Component({
selector: "hello",
template: `
<h1>game</h1>
`,
styles: [
`
h1 {
font-family: Lato;
}
`
]
})
export class HelloComponent implements AfterViewInit {
constructor(public elRef: ElementRef, private zone: NgZone) {
// The application will create a canvas element for you that you
// can then insert into the DOM.
}
public ngAfterViewInit(): void {
this.zone.runOutsideAngular(
(): void => {
const app: Application = new Application({
//view: this.myCanvas.nativeElement,
});
this.elRef.nativeElement.appendChild(app.view);
console.log("Plugins", app.renderer.plugins);
const sprite: Sprite = Sprite.from(
"https://avatars.githubusercontent.com/in/2740?s=64&v=4"
);
app.stage.addChild(sprite);
app.render();
}
);
}
}根据文档,默认行为应该是很少预先填充插件。但是,如果确实检查了是否设置了这些错误(参见下面示例中的控制台),就会产生上面的错误。
问题的重新讨论:https://stackblitz.com/edit/angular-zvqwsh?file=src/app/hello.component.ts
如果我确实在一个简单的设置中使用相同的pixi版本,它确实工作得很好。所以我猜是天使捆绑导致了这个问题,但我不知道是怎么引起的。因为代码显然存在于ESM包中。
发布于 2021-08-03 07:17:09
当我尝试调试它时,插件是在node_modules/pixijs/dist/esm/pixi.js中注册的,因为角项目没有导入它,插件没有正确注册。我补充说:
import * as PIXI from 'pixi.js';在文件顶部添加以下行,以避免树抖动,从而从最终包中删除pixi.js。
console.log(PIXI.VERSION);工作版本:https://stackblitz.com/edit/angular-2cwx4k?file=src/app/hello.component.ts
https://stackoverflow.com/questions/67091799
复制相似问题