Yummy2828 Posted August 10, 2018 Share Posted August 10, 2018 I'm using Typescript to code a canvas using pixi. I've been declaring initial variable names such as container1: PIXI.Container; container2: PIXI.Container; sprite1: PIXI.Sprite; sprite2: PIXI.Sprite; as so on. Container seems to work fine as I declare new containers in a function When I use PIXI.loader to declare the new sprite, pixiLoaderInit() { PIXI.loader .add(["directory of image"]) .load(setup); function setup() { this.sprite1 = PIXI.loader.resources["directory of image"].texture console.log("done"); } } I get the following errors on FireFox ERROR TypeError: "this is null" and Chrome ERROR TypeError: Cannot set property 'sprite1' of null at setup Any solutions to this? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 10, 2018 Share Posted August 10, 2018 first, "this" is from other place. Please learn about javascript scopes and differences between "function" and arrow ()=> . Second, You cant just add a directory that way pixi somehow gets list of files from it and loads everything, in web its just not possible. Please follow explanations at https://github.com/kittykatattack/learningPixi Quote Link to comment Share on other sites More sharing options...
Yummy2828 Posted August 11, 2018 Author Share Posted August 11, 2018 Thanks for the advice. I've encountered this sort of problem in the past and I wasn't aware of it in this situation. I guess the next time I see a null error when I'm not supposed to, I'll remember the new arrow function https://hackernoon.com/javascript-es6-arrow-functions-and-lexical-this-f2a3e2a5e8c4 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.