Jump to content

Pixi-particles Emitter position


Evar1ste
 Share

Recommended Posts

Hello,

First post there, little bit nervous :P

I am currently developing a little game using PIXI, but got stucked with pixi-particle related problem.
Link to game

As anyone can see my player 'spells' aka particles, are changing their respective position with their emitter (emitter and particles are moving).
What i want to achive is comet-like animation (like when mousemoving, using Pixi-particles-editor).

Let's proceed to the code.
 

import { ParticleContainer, loader } from 'pixi.js';
import { Emitter } from 'pixi-particles';
import { Spellbook as SPELLCONFIG } from './SpellTypes/Spellbook';



export default class Spell extends ParticleContainer {

    constructor(name, player) {

        super();
        super.setProperties({
            scale: true,
            position: true,
            rotation: true,
            uvs: true,
            alpha: true
        });

        this.name = name;
        this.playerName = player.name;

        this.spellEmitter = new Emitter(this, loader.resources.basicparticle.texture, SPELLCONFIG[name].emitter);
        this.spellEmitter.updateOwnerPos(player.x, player.y);

        this.direction = player.rotation;
        this.velocity = SPELLCONFIG[name].velocity;

    }

    update(delta) {

        const newX = this.spellEmitter.ownerPos.x + Math.sin(this.direction) * this.velocity;
        const newY = this.spellEmitter.ownerPos.y - Math.cos(this.direction) * this.velocity;
        this.spellEmitter.updateOwnerPos(newX, newY);
        this.spellEmitter.update(delta);


    }

}

Was trying to add resetTrackingPosition() before updateOwnerPosition() after analyzing pixi-particles example code. (and dozen of other solutions, but nothings worked as i intended)

Imho, theres something deeply misunderstood by me about pixi-particles system, so i have to ask here :)

Oh, whole game code can be found at my github project page. (Folder Spells is the one with particles code)

There are spells named "avada", "bariero", "stupefy" with their configuration (precisely - emitter settings) files.

PS. i am aware of particleContainers not being destroyed.

PS2. Sorry for my English, it's not my native. But tryin my best ;)

Link to comment
Share on other sites

I have an array of 'casted spells' in SpellManager object.
Updating game, updates every single particleContainer aka spell.

import Spell from './Spell';
import { Spellbook as SPELLBOOK } from './SpellTypes/Spellbook';

export default class SpellsManager {

    constructor(player, gameContext) {

        this.gameContext = gameContext;
        this.player = player;
        this.spellNames = SPELLBOOK.names;
        this.currentPlayerSpell = this.spellNames[0];
        this.castedSpells = [];

    }

    nextSpell() {

        let nextIndex = this.spellNames.indexOf(this.currentPlayerSpell);
        nextIndex = ++nextIndex % (this.spellNames.length);
        this.currentPlayerSpell = this.spellNames[nextIndex];

    }


    castCurrent() {

        const spell = new Spell(this.currentPlayerSpell, this.player);
        this.castedSpells.push(spell);
        this.player.parent.addChild(spell);

    }

    update(delta) {

        this.castedSpells.forEach(spell => {

            spell.update(delta);

        });

    }

}

 

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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