In this tutorial, we’ll use the Patch Editor to create an effect that responds to interactions with the screen of the device — like taps and swipes.
Download the sample content to follow along. If you open the finished project, you'll see we're going to build an effect with a clown nose and confetti.
The clown nose will get bigger when you pinch the screen and the confetti will appear in response to a long press.
To get started, open the unfinished version in the sample content folder.
You should see a 3D object that looks like a red nose in the Viewport and Simulator, attached to the face.
You'll should also see 3 particle systems listed in the Scene panel. They're called red emitter, yellow emitter and green emitter. Together, they create the confetti effect:
To start working with patches, open the Patch Editor:
There's already a simple patch graph in the Patch Editor:
The graph uses a face landmark patch, Nose, to fix the clown nose to the tip of the nose.
First you're going to add the interaction that changes the size of the clown nose. You'll use the Screen Pinch patch to do this - but there are all kinds of interaction patches to choose from.
Start by adding the patch that will detect a pinching movement on the device screen:
You'll see the new patch in the Patch Editor:
The Screen Pinch patch has four ports. We're only going to use the Scale output port, because we want to use this interaction to control the size of the clown nose.
To control all of the scale coordinates of the clown nose at once, you'll need to take the screen pinch gesture and convert it into one point. To do this you can use the Pack patch.
To add the patch:
Then, connect the Scale port in the Screen Pinch patch to each of the 3 input ports in the Pack patch:
Now you've converted the screen pinch gesture into one point, you can connect it to a patch representing the scale of the clown nose itself. To do this:
The scale of the clown nose should now change when you pinch the screen - use the Spark AR Player app to try it out.
As you can see in the Viewport and the Simulator, the confetti is visible all the time. Let’s change this using the Screen Tap and Hold patch.
First create the patch:
This patch has three ports. We're going to focus on the Gesture State port:
It outputs a boolean data type, which means at any point in time it's either true or false. In this graph, it means the tap and hold gesture is either detected or it isn't.
To tell Spark AR Studio what to do when a tap and hold is detected, you'll need to:
Next, you'll need to send this signal to the particle systems. The property that controls the rate at which particles are emitted is the Birthrate, so that's where you need to send the signal.
To send the signal to the particle system:
You’ll see 3 patches, representing the Birthrate of each particle system.
Connect the output port on the right hand side of the If Then Else patch to the Birthrate ports in each patch:
The confetti in your scene should now only appear when a long press is detected.
To test this, click the hamburger menu at the top of the Simulator, and select Simulate Touch:
Use Counter and If Then Else to show different things in response to interaction.
Make something happen in your effect when someone taps on an object.