threedollarbill Posted November 7, 2016 Share Posted November 7, 2016 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 More sharing options...
ForgeableSum Posted November 8, 2016 Share Posted November 8, 2016 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 More sharing options...
Tom Atom Posted November 8, 2016 Share Posted November 8, 2016 Hi, your onZipBinaryLoaded must return value - this is from one of my games: public onBinaryLoaded(key: string, data: ArrayBuffer) { return data; } threedollarbill 1 Link to comment Share on other sites More sharing options...
threedollarbill Posted November 10, 2016 Author Share Posted November 10, 2016 On 11/8/2016 at 3:54 PM, Tom Atom said: Hi, your onZipBinaryLoaded must return value - this is from one of my games: Ahh yes, thanks for this Tom! I saw this in the examples too just now ( https://phaser.io/examples/v2/loader/load-binary-file ). I should have looked at the examples first before posting here. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts