Getting Started - Chapter 6 - The Switch On Event

The Switch On Event

When we click the screen pointer on the fountain we want it to start. We do this by adding a function to an onPointerObservable to deal with a pointer down event that switches the particle system between stop and start.

let switched = false; //on off flag
scene.onPointerObservable.add((pointerInfo) => {
switch (pointerInfo.type) {
case BABYLON.PointerEventTypes.POINTERDOWN:
if(pointerInfo.pickInfo.hit) {
pointerDown(pointerInfo.pickInfo.pickedMesh)
}
break;
}
});
const pointerDown = (mesh) => {
if (mesh === fountain) { //check that the picked mesh is the fountain
switched = !switched; //toggle switch
if(switched) {
particleSystem.start();
}
else {
particleSystem.stop();
}
}
}
Start/Stop Particles on Click

Now we add this into the village world.

Add The Fountain To The Village

So far all the actions have been in daylight and now time moves to the night where we will need street lights.