Jump to content

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?

Link to comment
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 https://github.com/kittykatattack/learningPixi

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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