Last active
September 9, 2015 09:01
-
-
Save apostroll/b831c14f6d4ca63986a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Demo at http://codepen.io/anon/pen/gbXoXm | |
var game = new Phaser.Game(800, 600, Phaser.AUTO); | |
game.state.add('main', {create: create}); | |
game.state.start('main', true, false); | |
var emitter; | |
function create() { | |
var pSize = game.world.width / 12.5; | |
var bmpd = game.add.bitmapData(pSize, pSize); | |
// Create a radial gradient, yellow-ish on the inside, orange | |
// on the outside. Use it to draw a circle that will be used | |
// by the FireParticle class. | |
var grd = bmpd.ctx.createRadialGradient( | |
pSize / 2, pSize /2, 2, | |
pSize / 2, pSize / 2, pSize * 0.5); | |
grd.addColorStop(0, 'rgba(193, 170, 30, 0.6)'); | |
grd.addColorStop(1, 'rgba(255, 100, 30, 0.1)'); | |
bmpd.ctx.fillStyle = grd; | |
bmpd.ctx.arc(pSize / 2, pSize / 2 , pSize / 2, 0, Math.PI * 2); | |
bmpd.ctx.fill(); | |
game.cache.addBitmapData('flame', bmpd); | |
// Generate 100 particles | |
emitter = game.add.emitter(game.world.centerX, game.world.height, 100); | |
emitter.width = 3 * pSize; | |
emitter.particleClass = FireParticle; | |
// Magic happens here, bleding the colors of each particle | |
// generates the bright light effect | |
emitter.blendMode = PIXI.blendModes.ADD; | |
emitter.makeParticles(); | |
emitter.minParticleSpeed.set(-15, -80); | |
emitter.maxParticleSpeed.set(15, -100); | |
emitter.setRotation(0, 0); | |
// Make the flames taller than they are wide to simulate the | |
// effect of flame tongues | |
emitter.setScale(3, 1, 4, 3, 12000, Phaser.Easing.Quintic.Out); | |
emitter.gravity = -5; | |
emitter.start(false, 3000, 50); | |
} | |
function FireParticle(game, x, y) { | |
Phaser.Particle.call(this, game, x, y, game.cache.getBitmapData('flame')); | |
} | |
FireParticle.prototype = Object.create(Phaser.Particle.prototype); | |
FireParticle.prototype.constructor = FireParticle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
slow effect in mobile . tks