Particles 组件

Events

ParticleEnd
当粒子动画完成时

基于 Mr. Speaker 的 Parcycle,使用 MIT 协议,Leo Koppelkamm 移植。

注意:这需要canvas元素,如果浏览器不支持,它什么也不做。

对于实现细节,请检查源代码。

方法

Back to top

.particles()

public this .particles(Object options)
options

指定粒子行为和外观的选项映射集合。

例子

var options = {
  maxParticles: 150,
  size: 18,
  sizeRandom: 4,
  speed: 1,
  speedRandom: 1.2,
  // Lifespan in frames
  lifeSpan: 29,
  lifeSpanRandom: 7,
  // Angle is calculated clockwise: 12pm is 0deg, 3pm is 90deg etc.
  angle: 65,
  angleRandom: 34,
  startColour: [255, 131, 0, 1],
  startColourRandom: [48, 50, 45, 0],
  endColour: [245, 35, 0, 0],
  endColourRandom: [60, 60, 60, 0],
  // Only applies when fastMode is off, specifies how sharp the gradients are drawn
  sharpness: 20,
  sharpnessRandom: 10,
  // Random spread from origin
  spread: 10,
  // How many frames should this last
  duration: -1,
  // Will draw squares instead of circle gradients
  fastMode: false,
  gravity: { x: 0, y: 0.1 },
  // sensible values are 0-3
  jitter: 0,
  // Offset for the origin of the particles
  originOffset: {x: 0, y: 0}
};

Crafty.e("2D,Canvas,Particles").particles(options);
Back to top

.pauseParticles()

public this.pauseParticles()

pauseParticles 将会冻结正在执行的粒子。

例子

// start particle animation
var ent = Crafty.e("Particles").particles(someParticleConfig);

// and some time later, the gameplay is paused (or only
// a part of it is frozen)
ent.pauseParticles();
Back to top

.resumeParticles()

public this.resumeParticles()

resumeParticles 将会唤醒之前暂停的粒子。

粒子

// start particle animation
var ent = Crafty.e("Particles").particles(someParticleConfig);

// and some time later, the gameplay is paused (or only
// a part of it is frozen)
ent.pauseParticles();

// and we resume the particles again
ent.resumeParticles();