Everything you need to know to create an interactive augmented reality experience.
In this tutorial, we’ll use the Patch Editor to create an effect with 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:
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 the patches, open the Patch Editor by clicking the workspace icon in the toolbar and selecting Show/Hide Patch Editor. The Patch Editor will open below the Viewport.
There should already be a graph in the Patch Editor. It uses a face landmark patch - Nose - to fix the 3D object to the tip of the nose:
First, you're going to add an interaction that changes the size of the clown nose when you pinch the screen. You'll use the Screen Pinch patch to do this - but there are all kinds of interaction patches to choose from.
To do this, start by adding the patch that will detect a pinching movement on the device screen:
The Screen Pinch patch has four ports:
We're only going to use the Scale 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 we'll use the Point Pack patch.
Double-click in the Patch Editor again, and insert the Pack patch.
Then, connect the Scale port in the Screen Pinch patch to each of the 3 input ports on the Point Pack patch:
Now you've converted the screen pinch gesture into one point, you can connect it to 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, at the moment the confetti is visible all the time. Let’s change this using the Screen Long Press patch.
First, double-click anywhere in the Patch Editor, find the Screen Long Press patch and insert it.
This patch has three ports. We're going to focus on the State port:
It's a boolean data type, which means at any point in time, it's either true or false. In our case, this means the long press gesture is either detected or it isn't.
To tell Spark AR Studio what to do when a long press is detected, you'll need to:
Next, you'll need to send this signal to the particle systems in your scene. 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:
Find inspiration, see examples, get support, and share your work with a network of creators.Join Community