Jump to Main Content
Jump to Main Content

BlinkScript Create Particle Code Example



Description


This code example shows how to programatically create a particle system. All the code and assets are in the projects Scripts directory. You can download the project using the link above.

PostWorld.js


// Turn on debug so that Chat.printDebug() and Chat.dump() work
Chat.debugOutput = true;

// Display the stats panel in the bottom left corner of screen
Application.statsVisible = true;

// Turn on collisions, but allow the user to turn it off
Actor.setCollisionSetting( true, false );

// Turn on gravity, but allow the user to turn it off
Actor.setGravitySetting( true, false );

// Hide the avatar
Actor.showAvatar  = false;

// Hide the chat panel
Application.chatPaneVisible = false;

// Set ambient light for the scene
Scene.ambientLightColor = Color(0.5, 0.5, 0.5, 0);

// Create a point light
oPointLight = Scene.createPointLight( "SceneLight" );
oPointLight.position = Vector( 20, 300, 50 );

// Create the floor
var oGround = Scene.createGround( "MainFloor", "RustySteel", 3000.0, 3000.0, true );

// Add the Ogre head
oHeadEntity = Scene.createEntity( "OgreHead", "ogrehead.mesh" );
oHeadNode = Scene.createSceneNode( "OgreHeadNode" );
oHeadNode.attachObject( oHeadEntity );
oHeadNode.position = Vector( 0, 175, -500 );

// Create a particle system
oParticleSys = Scene.createParticleSystem( "FirstParticleSys", "General" );

// Create a scene node and attach the particle system to it
oParticleNode = Scene.createSceneNode( "ParticleNode" );
oParticleNode.attachObject( oParticleSys );

// Set the position of the scene node
oParticleNode.position = Vector( 0, 225, -500 );

// Set some settings for the particle system
oParticleSys.maxParticles = 400;
oParticleSys.materialName = "ParticleLensFlare";
oParticleSys.defaultWidth = 1;
oParticleSys.defaultHeight = 1;
oParticleSys.cullIndividually = false;
oParticleSys.renderer = oParticleSys.RENDERER_BILLBOARD;
oParticleSys.billboardType = oParticleSys.BILLBOARD_TYPE_POINT;

// Create a point particle emitter
oPointEmitter = oParticleSys.createEmitter( oParticleSys.EMITTER_POINT );
oPointEmitter.angle = 1.57;
oPointEmitter.color = Color( 1, 1, 1, 1 );
oPointEmitter.colorRangeStart = Color( 1, 1, 1, 1 );
oPointEmitter.colorRangeEnd = Color( 1, 1, 1, 1 );
oPointEmitter.direction = Vector( 0, -1, 0 );
oPointEmitter.emissionRate = 173.9;
oPointEmitter.position = Vector( 0,0, 0 );
oPointEmitter.velocity = 20;
oPointEmitter.minVelocity = 20;
oPointEmitter.maxVelocity = 20;
oPointEmitter.timeToLive = 3;
oPointEmitter.minTimeToLive = 3;
oPointEmitter.maxTimeToLive = 3;
oPointEmitter.duration = 3;
oPointEmitter.minDuration = 3;
oPointEmitter.maxDuration = 3;
oPointEmitter.repeatDelay = 8;
oPointEmitter.minRepeatDelay = 8;
oPointEmitter.maxRepeatDelay = 8;

// Create a ring particle emitter
oRingEmitter = oParticleSys.createEmitter( oParticleSys.EMITTER_RING );
oRingEmitter.angle = 0;
oRingEmitter.color = Color( 1, 1, 1, 1 );
oRingEmitter.colorRangeStart = Color( 1, 1, 1, 1 );
oRingEmitter.colorRangeEnd = Color( 1, 1, 1, 1 );
oRingEmitter.direction = Vector( 0,1, 0 );
oRingEmitter.emissionRate = 100;
oRingEmitter.position = Vector( 0,0, 0 );
oRingEmitter.velocity = 2;
oRingEmitter.minVelocity = 2;
oRingEmitter.maxVelocity = 2;
oRingEmitter.timeToLive = 2;
oRingEmitter.minTimeToLive = 2;
oRingEmitter.maxTimeToLive = 2;
oRingEmitter.duration = 3;
oRingEmitter.minDuration = 3;
oRingEmitter.maxDuration = 3;
oRingEmitter.repeatDelay = 8;
oRingEmitter.minRepeatDelay = 8;
oRingEmitter.maxRepeatDelay = 8;
oRingEmitter.width = 20;
oRingEmitter.height = 20;
oRingEmitter.depth = 20;

// Create a linear particle effector
oLinearAffector = oParticleSys.createAffector( oParticleSys.AFFECTOR_LINEAR_FORCE );
oLinearAffector.forceVector = Vector( 0, 10, 0 );
oLinearAffector.forceApplication = oLinearAffector.LINEAR_FORCE_ADD;

// Create a rotation particle affector
oRotationAffector = oParticleSys.createAffector( oParticleSys.AFFECTOR_ROTATION );
oRotationAffector.rotationSpeedRangeStart = 2.61;
oRotationAffector.rotationSpeedRangeEnd = 3.05;
oRotationAffector.rotationAngleRangeStart = 1.48;
oRotationAffector.rotationAngleRangeEnd = 6.14;

// Create a scaler affector
oScalerAffector = oParticleSys.createAffector( oParticleSys.AFFECTOR_SCALE );
oScalerAffector.scale = 5;

// Create a color fader affector
oColorFaderAffector = oParticleSys.createAffector( oParticleSys.AFFECTOR_COLOR_FADER );
oColorFaderAffector.red1 = -0.4;
oColorFaderAffector.green1 = -0.4;
oColorFaderAffector.blue1 = -0.4;
oColorFaderAffector.alpha1 = -0.4;

// Create a color fader 2 affector
oColorFader2Affector = oParticleSys.createAffector( oParticleSys.AFFECTOR_COLOR_FADER2 );
oColorFader2Affector.red1 = 0.3171;
oColorFader2Affector.green1 = -0.1304;
oColorFader2Affector.blue1 = -0.3034;
oColorFader2Affector.alpha1 = -0.999;
oColorFader2Affector.red2 = 0.5175;
oColorFader2Affector.green2 = 0.2174;
oColorFader2Affector.blue2 = -0.08628;
oColorFader2Affector.alpha2 = -0.147;
oColorFader2Affector.stateChange = 2;


Related BlinkScript Examples
?????? ?????? ?????? ??????