Jump to content

Nightmare with Particle Storm & sprites


wamballa
 Share

Recommended Posts

Hi there

How can I have fancy particlestorm trails coming out of by sprite bullets and do collision detection?

I've managed to get the basic PS emitter example working. But there is no way of getting the emitter position or doing collision detection between the emitter and another object (that I know of)

I've tried to put a sprite over the emitter but it's hard to match the velocities and stop the emitter when I want to kill the bullet.

I've tried to create a sprite with a render texture but nothing happens. Also tried adding the emitter as a child.

I presume I need to create a sprite and attach the emitter to it but am now stuck.

Any help is much appreciated and code below.

Thanks!

var game = new Phaser.Game(400, 300, Phaser.AUTO, 'Particles', { preload: preload, create: create, update: update, render: render });

var manager = null;
var emitter = null;
var object;
var bullet = {
    image: 'bullet',
    anchorX : 0.8,
    anchorY : 0.5,
    vy: -8.0,
    scale: 0.5,
    rotation: -90.0,
    emit: {
        name: 'data',
        value: 0.07
    }
};
var data = {
    lifespan: 6000,
    image: 'white',
    scale: 0.5,
    blendMode: 'ADD',
    hsv: { initial: 0, value: 359, control: 'linear' },
    vx: { min: -0.5, max: 0.5 },
    vy: { min: -1, max: -2 }
};
var player;

function preload() {
    game.load.script('particlestorm', './assets/particle-storm.min.js');
    // game.forceSingleUpdate = true;
    game.load.image('bullet', './assets/bullet.png');
    game.load.image('white', './assets/white.png');
    game.load.image('player', './assets/turret.png');
}

function create() {
    manager = this.game.plugins.add(Phaser.ParticleStorm);
    manager.addData('bullet', bullet);
    manager.addData('data', data);

    //emitter = manager.createEmitter();
    emitter = manager.createEmitter(Phaser.ParticleStorm.RENDERTEXTURE);
    emitter.addToWorld();

    //player = game.add.sprite ( 100, 100,emitter.renderer.renderTexture);
    player = game.add.sprite ( 100, 100, 'player');
    game.physics.enable(player, Phaser.Physics.ARCADE);
    player.enableBody = true;
    //player.addChild(emitter);
}

function fire(pointer) {
    emitter.renderer.display.visible = true;
    console.log ("PointerX= "+pointer.x);
    player.reset (pointer.x,300);
    player.body.velocity.y = -500;
    emitter.emit('bullet', pointer.x, 300);
}

function update(){
    game.input.onDown.add(fire, this);
    if (player.body.y < 50 ){
        player.kill();
        emitter.renderer.display.visible = false;
    }
}

function render() {
    game.debug.text('Click to fire', 32, 32);
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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