Jump to content

Loaded binary file never gets added to the cache? (unable to access it)


threedollarbill
 Share

Recommended Posts

I am able to load a binary file but I cannot access it from the cache. I seem to be doing everything correctly.

I am loading a zip file by doing this:

let zipURL:string = Constants.HOST_BASE_PATH + "puzzles/starter_puzzle.zip";
let zipLoader:Phaser.Loader = new Phaser.Loader(this.game);
zipLoader.binary("starter_puzzle", zipURL, this.onZipBinaryLoaded, this);
zipLoader.start();

private onZipBinaryLoaded(cacheKey:string, binaryData:any):void
{
     // this succeeds, and i do some processing here...
}

Later on in the game, I try to access that binary file from the cache, but I cannot seem to access it. I've tried the following:

this.game.cache.checkBinaryKey("starter_puzzle"); // this returns false

this.game.cache.getBinary("starter_puzzle"); // this returns a "not found in cache" warning

I wonder what I'm missing here. I've even tried to explicitly add it to the cache, but still I am unable to access it later on.

private onZipBinaryLoaded(cacheKey:string, binaryData:any):void
{
     // here i explicitly add it to the cache do some further processing...
     
     this.game.cache.addBinary(cacheKey, binaryData);

     // ...do some further processing...
}

 

Link to comment
Share on other sites

I don't 100% understand your code because I don't use TypeScript, but make sure that you are using the default loader created when you create a new Phaser.Game. You can reference it with game.load. You might be creating a new Phaser.Loader which can be problematic. 

You should also try using game.load.binary() instead of trying to add the zip directly to the cache. Because the zip is a URL, I assume it needs to be loaded. You would only be able to put it directly in the cache with addBinary if it were already loaded into the browser (which isn't the case for a URL). 

Hope that helps. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...