JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.jsdelivr.net/phaser/2.4.6/phaser.min.js"></script>
How to disable gravity on particles?
<div id="game">
</div>
JavaScript
// test program
var CANVAS_WIDTH = 600;
var CANVAS_HEIGHT = 400;
var SPRITE_SIZE = 60;
var game = new Phaser.Game(CANVAS_WIDTH, CANVAS_HEIGHT, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var emitter = null;
// -------------------------------------
// PHASER GAME FUNCTIONS
// -------------------------------------
function preload() {
game.load.spritesheet('particles', 'img/particles.png', 32, 32);
}
function create() {
// set stage physics
game.stage.backgroundColor = 0x808080;
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.arcade.gravity.y = 1000; // <- set gravity for player, enemies etc.
// add a particle emmiter
emitter = game.add.emitter(0, 0, 200); // x=0, y=0, maxParticles=200
emitter.makeParticles('particles', [0, 1, 2, 3]);
//emitter.setXSpeed(-120, +120);
//emitter.setYSpeed(-120, +120);
emitter.setXSpeed(0, 0); // testing; particles should not move at all
emitter.setYSpeed(0, 0);
emitter.setRotation(0, 0);
emitter.gravity = 0; // no gravity on particles? this doesn't work?
// test explode one particle
emitter.x = CANVAS_WIDTH / 2;
emitter.y = CANVAS_HEIGHT / 2;
emitter.start(true, 2000, null, 1); // explode=true, lifespan=800, freq=null, quantity=1
}
function update() {
// noting here
}
function render() {
var testparticle = emitter.getFirstExists();
if (testparticle) {
game.debug.bodyInfo(testparticle, 10, 10);
}
}