【发布时间】:2020-09-21 10:28:10
【问题描述】:
我在 Vue.js 中将 Sprite 添加到我的 PIXI Particles 容器时遇到问题。这在我仅在脚本中运行 PIXI 时有效,但在 Vuejs 中每个 new PIXI.Sprite.from("../assets/plainSquare.png") 不显示
我的目标是以这种方式生成一个静态的正方形网格:
setup() {
// making a 30 x 16 grid of tiles
const columns = 30;
const rows = 16;
for (let i = 0; i < columns * rows; i++) {
const square = PIXI.Sprite.from("../assets/plainSquare.png");
square.width = square.height = 25;
square.x = (i % columns) * 32;
square.y = Math.floor(i / columns) * 32;
// add squares to stage
this.container.addChild(square);
}
}
如果您需要,这里是完整的代码框:https://codesandbox.io/s/pixi-sprite-loading-cn7re?file=/src/App.vue
【问题讨论】:
-
你的代码中的路径应该是
"./assets/..."。