Sign in to follow this  

Cannot assign sprite to class variable

Recommended Posts

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() {
			.add(["directory of image"])

	function setup() {
			this.sprite1 = PIXI.loader.resources["directory of image"].texture

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?

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.