Skip to content

Instantly share code, notes, and snippets.

@oodavid
Created December 16, 2014 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oodavid/fd9213e0370e50bcb339 to your computer and use it in GitHub Desktop.
Save oodavid/fd9213e0370e50bcb339 to your computer and use it in GitHub Desktop.
GameClosure > Particles
/** MOLECULE MATCH - Particles
*
* Utility View for GameClosure DevKit to add an
* explosion of Particles anywhere on the screen.
*
* Modified for github
*
* @author David "oodavid" King
* @copyright Copyright (c) 2014 +
*/
import device;
import ui.ParticleEngine as ParticleEngine;
var gx = Math.ceil(Math.min(device.width,device.height)/20); // A fitting size for the screen
// Extend the ParticleEngine
exports = Class(ParticleEngine, function(supr){
this.init = function(opts){
supr(this, 'init', [merge(opts, {
canHandleEvents: false,
width: 1,
height: 1,
initCount: 60
})]);
this.tick = this.runTick;
};
this.addParticles = function(x, y, type, silent){
var n = 20;
// Play the noise?
if(!silent){
GC.app.audio.play('particles_'+type);
}
// Add particles to the specified spot
var particleObjects = this.obtainParticleArray(n);
for (var i = 0; i < n; i++) {
// When using 'confetti' there are a number of variants, cycle through them
icon = type == 'confetti' ? 'confetti_'+(i%4) : type;
// Basic settings
var pObj = particleObjects[i];
pObj.image = 'resources/images/particles/'+icon+'.png';
pObj.width = (gx*2);
pObj.height = (gx*2);
pObj.anchorX = (gx);
pObj.anchorY = (gx);
// Position
pObj.x = x-(gx);
pObj.y = y-(gx);
pObj.r = Math.random() * 6.3;
// Movement
pObj.delay = i * 5;
pObj.dx = (gx*20) - Math.random() * (gx*40);
pObj.dy = (gx*20) - Math.random() * (gx*40);
pObj.ddy = (gx*10); // gravity is constant
pObj.dr = 6*(Math.random()-0.5);
pObj.ddopacity = -1;
pObj.ttl = 2000;
}
this.emitParticles(particleObjects);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment