Particle Engine

You can define and fire particle emitters inside .bani animation files:

Example

  "emitters": {
    "1": {
      "relative": true,
      "quantity": 30,
      "limit": 300,
      "draworder": "down",
      "sound": ["crack"],
      "soundchance": 100,

      "particles": [
        {
          "lifetime": [0.9,1.3],
          "image": "bbuilder_streak.png",
          "mode": "add",
          "alpha": 1,
          "zoom": 0.9,
          "red": [0.6, 1],
          "green": [0.6, 1],
          "blue": 1,
          "angle": [0, 360],
          "speed": 192,
          "emitatend": 2,

          "effects": [
            {"type":"range","time":[0.5,1],"attr":"alpha","mode":"replace","value":[1,0.5]},
            {"type":"range","time":[0.8,1.3],"attr":"zoom","mode":"replace","value":[0.9,0.2]}
          ]
        }
      ]
    },
    "2": {
      "relative": true,
      "quantity": 5,
      "limit": 300,
      "draworder": "down",
      "sound": ["crack"],
      "soundchance": 10,

      "particles": [
        {
          "lifetime": 1,
          "image": "bbuilder_flare.png",
          "mode": "add",
          "alpha": 1,
          "zoom": [0.4, 0.5],
          "red": [0.2, 0.5],
          "green": 0.6,
          "blue": 1,
          "angle": [0, 360],
          "speed": 64,

          "effects": [
            {"type":"range","time":[0.2,1],"attr":"alpha","mode":"replace","value":[1,0]}
          ]
        }
      ]
    }
  }

Activating Emitters

Firing the emitter: you can specify which emitter to fire, and at which position it should spawn the particles. As alternative you can also just type "emit":1, then it will fire emitter 1 at the position of the emitter.

  "frames":[
    {
      "directions": [
        [[2,0,2], [5,-48,-207]]
      ],
      "duration": 500,
      "emit": [{"emitter":"1", "position":[16,0,144]}]
    }
  ]

Weather Example

Weather Particle Effect stored inside a BANI

{        
  "filetype": "bbuilderani",
  "aniversion": 1,
  "copyright": "2017 iAppsBeats LTD",

  "options": {
  },

  "defaults": {
  },      

  "emitters": {
    "1": {
      "position": ["RANDOMSCREENX", "RANDOMSCREENY", 100],
      "relative": false,
      "interval": 0.05,
      "reduceonmobile": true,
      "quantity": 2,
      "limit": 300,
      "draworder": "up",
      "screenwrap": true,

      "particles": [
        {
          "lifetime": [0.9,1.3],
          "image": "bbuilder_snowflake.png",
          "mode": "add",
          "alpha": 1,
          "zoom": [0.25, 0.35],
          "red": [0.6, 1],
          "green": [0.6, 1],
          "blue": 1,
          "rotation": [0, 360],
          "angle": 3.14,
          "speed": [15,20],
          "zangle": -100,
          "gravity": 0,
          "spin": [-0.15, -0.05],
          "removeatground": false,
          "emitatend": 2,

          "effects": [
            {"type":"range","time":[0.5,1],"attr":"alpha","mode":"replace","value":[1,0.5]}
          ]
        }
      ]
    },
    "2": {
      "relative": false,
      "position": [0, 0, 0],
      "quantity": 1,
      "limit": 300,
      "screenwrap": true,

      "particles": [
        {
          "lifetime": 0.5,
          "image": "bbuilder_snowflake.png",
          "mode": "add",
          "alpha": 1,
          "zoom": [0.25, 0.3],
          "red": 0.3,
          "green": [0.3, 0.6],
          "blue": 1,
          "angle": 0,
          "rotation": [0, 360],
          "speed": 0,
          "spin": 0,
          "gravity": 0,
          "removeatground": false,

          "effects": [
            {"type":"range","time":[0.1,0.5],"attr":"alpha","mode":"replace","value":[1,0]}
          ]
        }
      ]  
    }      
  },      

  "sprites": {
     "1": {"gfx":"bbuilder_smoke1.png", "bounds": [0, 0, 128, 128]}
  },

  "frames": [
  ]  
}

Scripted Emitter

For testing, client-side scripts can also assign emitters directly to this.emitters and player.emitters, bypassing the animation file:

function onUpdated() {
    this.ani = "sign_jump";
    this.emitters = {
      firework: {
        "position": [16,0,0],
        "relative": false,
        "interval": 0.2,
        "quantity": 5,
        "limit": 300,
        "draworder": "down",
        "sound": ["crack"],
        "soundchance": 10,

        "particles": [
          {
            "lifetime": 1,
            "image": "bbuilder_flare.png",
            "mode": "add",
            "alpha": 1,
            "zoom": [0.4, 0.5],
            "red": [0.2, 0.5],
            "green": 0.6,
            "blue": 1,
            "angle": [0, 360],
            "speed": 100,

            "effects": [
              {"type":"range","time":[0.2,1],"attr":"alpha","mode":"replace","value":[1,0]}
            ]
          }
        ]
      }
    };
}