2015-11-08 75 views
0

我是使用RequireJS加載模塊,特別是加載類似CreateJS的庫的新手。我想在SoundJS上使用PreloadJS。我通過RequireJS正確加載了SoundJS,到目前爲止我沒有問題。我遇到的問題是PreloadJS。我用這種方式加載:使用RequireJS加載PreloadJS

require.config(
    { 
    paths : 
    { 
     soundjs : 'core/soundjs-0.6.1.min' 
     , preloadjs : 'core/preloadjs-0.6.1.min' 
    } 

    ,shim : 
    { 
     'preloadjs' : { exports : "createjs" } 
     , 'soundjs' : { exports : "createjs.Sound" } 
    } 
    }); 

require(['src/MainGameScene' , 'src/Runner' , 'core/pixi.js' , 'core/tween.min' , 'preloadjs' , 'soundjs' ] 
, function(MainGameScene , Runner , PIXI, TWEEN , PreloadJS , SoundJS) 
{ 
    console.log("Endless Runner modules loaded."); 

    var screenSize = { width : 960 , height : 500}; 
    var renderer = PIXI.autoDetectRenderer(screenSize.width , screenSize.height); 

    new PIXI.loaders.Loader() 
    .add("_assets/textures/p1_walk/Von.json") 
    .add("_assets/textures/p2_walk/Don.json") 
    .add("_assets/textures/p3_walk/Bon.json") 
    .add("_assets/textures/tiles.json") 
    .add("_assets/textures/textures.json") 
    .once("complete" , 
     function() 
     { 
     var queue = new PreloadJS(); 
     SoundJS.alternateExtensions = ["mp3" , "ogg" , "wav" ]; 
     queue.installPlugin(SoundJS); 
     queue.addEventListener("complete" , onFinishedLoading); 
     queue.loadManifest(
      [ 
      {id : "bgm1" , src : "_assets/bgm/bgm.mp3"} 
      ,{id : "jump" , src : "_assets/sfx/jump.wav" } 
      ,{id : "pickupcoin" , src : "_assets/sfx/pickupcoin.wav" } 
      ]); 
     }) 
    .load(); 

    function onFinishedLoading() 
    { 
    new MainGameScene(renderer , screenSize); 
    } 

    document.body.appendChild(renderer.view); 
}); 

當我運行調試它表明我,PreloadJS對象具有這個特性,我認爲這不是PreloadJS的一部分。我還檢查了原型是否正確,但我以Object爲原型:

noConflict: function() 
parse : function parse() 
runInContext : function a(b, d) 
stringify : function stringify() 
__proto__ : Object 

我還錯過了什麼?此外,我試圖墊片PreloadJS是這樣的:

'preloadjs' : { exports : "createjs.LoadQueue" } 
    , 'soundjs' : { exports : "createjs.Sound" } 

但我仍然得到這些屬性的對象。我需要RequireJS,所以我可以讓我的SoundJS有一個可靠的預加載器。我找不到任何有關RequireJS使用PreloadJS的文章,所以我相信我做錯了什麼,非傳統的和無證的,所以我會很感激任何幫助。

+1

聽起來像在PreloadJS中捆綁的JSON類導致了問題。 – Lanny

+0

我現在有這個完全相同的問題。你有沒有找到修復程序?如果我找到一個,我一定會在這裏發佈。 – dudewad

+1

我開了一個問題:https://github.com/CreateJS/PreloadJS/issues/171 – dudewad

回答

3

好吧,它解決了。這並不理想,但preloadjs並不是與AMD一起編寫的。 如果你的項目絕對需要你通過涼亭來包含你的依賴關係,或者這可能是次優的,但面對絕對沒有其他修復,我很滿足於此。

基本上,把你的preloadjs的版本,幷包住整個文件中定義()調用:

define(function(){ 
    //Paste the contents of preloadjs here 
    //After all the preloadjs code you need to return the reference to createjs: 
    return this.createjs 
}); 

該版本添加到您的依賴列表,一切都應該正常工作。

+0

勻場解決方案適用於0.4.x,但自0.6.x以來似乎您的解決方案是必要的。不完美,但比沒有好。 – Micros