moleboy Posted August 30, 2014 Share Posted August 30, 2014 I'm not sure what I'm doing wrong but the onComplete is triggering when the JSON is loaded. I thought it should wait until the PNG spritesheet that the JSON refers to is loaded too? Any help would be greatly appreciated. Here's my codeloadAssets: function(){ if(window.devicePixelRatio>1){ this.spriteSheetRef='img/processed/spritesheet_hires.json'; } else { this.spriteSheetRef='img/processed/spritesheet.json'; } this.loader = new PIXI.SpriteSheetLoader(this.spriteSheetRef,false); this.loader.onComplete = this.onAssetsLoaded(this); this.loader.load();},onAssetsLoaded: function(me){ me.assetsLoaded = true; console.log("assets loaded");} Quote Link to comment Share on other sites More sharing options...
moleboy Posted August 30, 2014 Author Share Posted August 30, 2014 Doh! Schoolboy error!! I was invoking the onComplete function right away by adding (this) to the this.loader.onComplete = this.onAssetsLoaded Why it took me so long to find it I'll never know! Quote Link to comment Share on other sites More sharing options...
Sebi Posted August 31, 2014 Share Posted August 31, 2014 this.loader.onComplete = this.onAssetsLoaded.bind(this);That way "this" refers to the right scope and you don't need your "me" var. Quote Link to comment Share on other sites More sharing options...
xerver Posted August 31, 2014 Share Posted August 31, 2014 this.loader.onComplete = this.onAssetsLoaded(this);This does not do what you think it does, this immediately invokes your onAssetsLoaded function and assigns the results (undefined) to onComplete. Sebastian's reply is what you are looking for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.