Javascript 如何正确导入pixi声音(pixi JS)
这可能是一个愚蠢的问题,但如何正确导入pixi声音 我的问题是:Javascript 如何正确导入pixi声音(pixi JS),javascript,html,import,pixi.js,Javascript,Html,Import,Pixi.js,这可能是一个愚蠢的问题,但如何正确导入pixi声音 我的问题是: import * as PIXI from "pixi.js"; import PIXI_SOUND from "pixi-sound"; const EFFECT_SOUNDS = [...list of music] for (let name in EFFECT_SOUNDS) { PIXI.Loader.shared.add(name, EFFECT_SOUNDS[name]); } ... more logi
import * as PIXI from "pixi.js";
import PIXI_SOUND from "pixi-sound";
const EFFECT_SOUNDS = [...list of music]
for (let name in EFFECT_SOUNDS) {
PIXI.Loader.shared.add(name, EFFECT_SOUNDS[name]);
}
... more logic
PIXI.Loader.shared.load(function(loader, resources) {
if (resources[sound]) {
// this is where the issue is
resources[sound].sound.play();
resources[sound].sound.speed= 0.5;
}
});
在上面的代码中,资源[sound].sound.play
和其他属性,如存在
、速度
、停止
等,都不存在
我尝试将代码更改为:
import * as PIXI_SOUND from "pixi-sound";
但这不起作用
我还尝试了PIXI\u SOUND.Loader
,但这将抛出一个错误。这对我很有效
import * as PIXI from 'pixi.js';
window.PIXI = PIXI; // this seems optional
import 'pixi-sound';
如果您正在使用,可以这样导入
import { Container, withPixiApp } from '@inlet/react-pixi';
import { default as PIXI_SOUND } from 'pixi-sound';
PIXI_SOUND.add(key, {
url: url,
preload: true,
loaded: (err, sound) => {
if (err) {
console.warn(`load sound ${key} - ${url} error: ${err}`)
} else {
console.log(`loaded sound ${key} - ${url}: ${sound.duration} seconds`)
}
}
})
你用什么捆绑你的代码?这可能是捆绑机配置的问题(例如,缺少处理cjs/esm模块的插件)。