Jump to content

Deep problem with PIXI


Recommended Posts

Hi guys,

I have a very particoular problem with PIXI.


Pratically I have a component that loads images and apply it in an async way when they are loaded:

sprite.loader = new PIXI.ImageLoader(url);sprite.loader.onLoaded = function () {         var texture;    // Texture to apply            // Check if a crop was passed            if (typeof crop !== 'undefined') {                // Create a new Texture by cropping the loaded Texture                texture = new PIXI.Texture(PIXI.TextureCache[url], crop);            } else {                texture = PIXI.TextureCache[url];            }            // Apply the Texture to the Sprite            self.applyTexture(sprite, texture, size, zoom);            // Invoke the callback if specified            if (typeof callback === 'function') {                callback(sprite);            }};

Now I have another component that sets the Sprite in a relative SpriteBatch, based on its BaseTexture:

        // Get the ID of the Texture        textureId = sprite.texture.baseTexture.imageUrl;        // Get the SpriteBatch relative to the Texture        spriteBatch = self.SpriteBatches[sprite.texture.baseTexture.imageUrl];        // Check if there exist a SpriteBatch for the Texture, otherwise create it.        // (to improve performance a SpriteBatch should have only Sprites with the same BaseTexture)        if (typeof spriteBatch === 'undefined') {            spriteBatch = new PIXI.SpriteBatch();                                  // Create the SpriteBatch container            self.SpriteBatches[sprite.texture.baseTexture.imageUrl] = spriteBatch; // Store it            self.container.addChild(spriteBatch);         // Add it to the main Container in the Stage        }        // Get the Sprite parent (current container)        parent = sprite.parent;        // Add the Sprite in the SpriteBatch        spriteBatch.addChild(sprite);}

Now it seems to work, but when it loads a new Texture for the sprites (the first code I wrote), it gives the error:

Uncaught TypeError: Cannot read property 'x0' of null


Do you know what could it be?

Link to comment
Share on other sites

This is the way I am applying texture:

self.applyTexture = function (sprite, texture, size, zoom) {        // Set Texture to Sprite        sprite.setTexture(texture);        // Update Sprite size          this.updateSpriteSize(sprite, zoom);    };

And this is the call stack:
PIXI.WebGLFastSpriteBatch.renderSprite pixi.dev.js:8200

PIXI.WebGLFastSpriteBatch.render pixi.dev.js:8135

PIXI.SpriteBatch._renderWebGL pixi.dev.js:2243

PIXI.DisplayObjectContainer._renderWebGL pixi.dev.js:1678

PIXI.DisplayObjectContainer._renderWebGL pixi.dev.js:1678

PIXI.DisplayObjectContainer._renderWebGL pixi.dev.js:1678

PIXI.WebGLRenderer.renderDisplayObject pixi.dev.js:6680

PIXI.WebGLRenderer.render pixi.dev.js:6610


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...