Announcement

Collapse
No announcement yet.

Particle Engine

Collapse
This is a sticky topic.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Particle Engine

    This is not exactly about scripting, but somehow related: the new particle engine.

    You can define and fire particle emitters inside .bani animation files:
    - Create emitters, with one or more particle templates
    - Fire the emitter with command "emit" inside single animation frames, or as a cascade action in particles. Or just define a position and an interval, then the emitter will fire automatically each few moments.
    - Use the effects-array to define how the particles change over time, such as fading out or zooming out.

    Example:

    Code:
      "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]}
              ]
            }
          ]
        }
      },
    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.

    Code:
      "frames":[
        {
          "directions": [
            [[2,0,2], [5,-48,-207]]
          ],
          "duration": 500,
          "emit": [{"emitter":"1", "position":[16,0,144]}]
        }
      ];
    Last edited by Stefan; 07-06-2017, 09:28 PM.
    Also known as Daddy and bomber

  • #2
    Weather is also defined in .bani files and configured in weatherzones.json:
    Example for the weather animation:

    Code:
    {        
      "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": [
      ]  
    }
    Configuration of a weather zone (right now static, can later be made dynamic):

    Code:
    {
        "weatherzones": [
            {
                "map":"main",
                "zones": [
                    {"x":0, "y":0, "w":256, "h":256, "weather":"weather_snow"}
                ]
            }
        ]
    }
    Also known as Daddy and bomber

    Comment

    Working...
    X