Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'x' of null #37

Closed
viveleroi opened this issue Dec 29, 2016 · 2 comments
Closed

Cannot read property 'x' of null #37

viveleroi opened this issue Dec 29, 2016 · 2 comments

Comments

@viveleroi
Copy link

Trying this project out for a PIXIjs v4.3.0 project. I'm using pixi-particles 2.0.0.

I'm loading a rain system, taken from your interactive generator with some tweaks from the base config.

Following the example on the readme, I've initialized the emitter with my container and emitter config, set emit = true and am calling the update method.

Yet with just these few steps, it's breaking with the error:

Cannot read property 'x' of null:
node_modules/pixi-particles/dist/pixi-particles.js:1519
		var curX = this.ownerPos.x + this.spawnPos.x;

Here's an example of my class:

const rain = require('../particles/rain.json');

// Load pixi particles, which patches PIXI
require('pixi-particles/dist/pixi-particles');

module.exports = class Weather {
    constructor() {
        // Initialize a render container
        this.container = new PIXI.Container();

        this.emitter = this.initRainEmitter();

        PIXI.ticker.shared.add(this.tick, this);
    }

    initRainEmitter() {
        return new PIXI.particles.Emitter(this.container, rain);
    }

    start() {
        this.raining = true;
        this.emitter.emit = true;
    }

    tick(delta) {
        if (this.raining) {
            this.emitter.update(delta);
        }
    }
};

This class is then loaded in my game by a parent container, like this:

this.weather = new Weather();
this.container.addChild(this.weather.container);
this.weather.start();
@amrelhady
Copy link

Are you missing art parameter when initialising Emitter?

https://github.com/pixijs/pixi-particles/blob/master/examples/js/ParticleExample.js#L118

emitter = new PIXI.particles.Emitter(
	emitterContainer,
	art,
	config
);

art is array of particle images. For example:

art = [PIXI.Texture.fromImage('img/particles.png')]

@andrewstart
Copy link
Contributor

Sorry, this one fell through the cracks while I was on vacation. amrelhady is correct - the 2nd parameter of the Emitter constructor is one of or an array of PIXI.Texture instances you have prepared, or urls to images to load (passed to PIXI.Texture.fromImage()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants