Evar1ste Posted February 11, 2018 Share Posted February 11, 2018 Hello, First post there, little bit nervous 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 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 11, 2018 Share Posted February 11, 2018 emitters work with seconds in "delta" parameter. Pixi ticker gives you 1.0 as one frame, (1/60.0 of second). Where do you call that "update" thing? Evar1ste 1 Quote Link to comment Share on other sites More sharing options...
Evar1ste Posted February 11, 2018 Author Share Posted February 11, 2018 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); }); } } Quote Link to comment Share on other sites More sharing options...
Evar1ste Posted February 11, 2018 Author Share Posted February 11, 2018 Ok, i changed "spell.update(delta)" to "spell.update(delta/60.0)" and now it works perfectly well. (excluding one spell but i think it's emitter settings related) Thank you for quick response ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.