我试图设置一个简单的示例pixi-viewport。它可以与Pixi.js正常运行,但甚至认为找到了pixi-viewport的脚本(viewport.js),我得到:
未捕获的TypeError:视口不是构造函数
这是HTML文件:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Pixi</title>
</head>
<script src="pixi/pixi.min.js"></script>
<script src="pixi/viewport.js"></script>
<body>
<script type="text/javascript">
let Application = PIXI.Application,
loader = PIXI.loader,
resources = PIXI.loader.resources,
Sprite = PIXI.Sprite;
Graphics = PIXI.Graphics
//Create a Pixi Application
let app = new Application({
width: 953,
height: 409,
backgroundColor: 0xFFFFFF
});
const viewport = new Viewport({
screenWidth: window.innerWidth,
screenHeight: window.innerHeight,
worldWidth: 1000,
worldHeight: 1000,
interaction: app.renderer.plugins.interaction // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
})
// add the viewport to the stage
app.stage.addChild(viewport)
</script>
</body>
</html>
答案 0 :(得分:0)
因此,事实证明,自Pixi v5起,对window.Viewport的直接访问已退出。
您需要使用某种构建系统(如包裹,汇总,Webpack等)。这样一来,您就可以从npm中提取库了,并使您的生活更轻松。