Clear
Back

As a result of the coronavirus (COVID-19) outbreak, we have a reduced capacity to review effects and delays in publishing are expected. Learn more.

There may be differences between your version of Spark AR Studio and this tutorial because the product is currently in beta and we update it regularly.

Tutorial: Holiday Photo

In this tutorial you'll build a world effect, visible through the back camera of a mobile device. In the effect, a 2D photo with dynamic text shows the date and location. You'll use the Patch Editor to add interactivity, so the frame changes color and a clicking sound plays when it's tapped:



Download the sample content to follow this tutorial. You can adapt any of the assets in this effect in your own projects.

Learn about:

  1. Adding 2D objects, textures and materials to create the photograph frame.
  2. Using dynamic text.
  3. Changing the color of the frame.
  4. Adding audio.

To get started open the unfinished effect in the sample content folder. We've already imported the assets you'll need to help you get started quickly. We've removed the directional and ambient lighting from the scene. This is a good idea when you're creating effects with 2D objects, as they don't need lighting to add depth to objects.

Creating the photo frame

This project uses two rectangles and a 2D Text object to create the frame. One rectangle contains the custom texture and the other contains the colored overlay.

Adding the 2D objects

We're going to add all the objects at the same time and then assign them to layers so you can clearly see what you're building.

Insert:

  1. A canvas. You'll use this to group the other objects, so you can transform them all at the same time.
  2. 2 rectangles, both as children of the canvas.
  3. A 2D text object, again as a child of the canvas.

Your project should look like this:



It's worth renaming the objects to help you keep track. Rename:

  • The first rectangle rect_frame
  • The second rectangle rect_overlay.
  • The text object dynamic_text.

Layers

You'll need 3 layers in this effect, to control the order objects render in.

There will already be 2 layers in the project, named frame_layer and color_overlay_layer. In the Layers panel, create 1 more layer and drag to position it above the frame_layer.

To keep track of layers, it's a good idea to rename them. We've called:

  1. The first layer text_layer.
  2. The second layer frame_layer.
  3. The third layer color_overlay_layer.

Back in the Scene panel, assign:

  1. The dynamic text to text_layer.
  2. The canvas and rect_frame to frame_layer.
  3. The rectangle overlay to color_overlay_layer.

Editing the canvas

First edit the canvas. Because the rectangles are children of the canvas, they will take on any changes made to it.

In the Inspector, change the Mode from Camera Space to World Space.



Because the canvas is in World Space it will no longer scale with the screen of the device. This allows you to change its Transformations. In the Inspector, change:

  1. The Position to -0.013 on the X axis - the canvas will move to the side slightly.
  2. The Scale to 0.0005 for the X, Y and Z values - the canvas will get slightly smaller.
  3. The Rotation to 5 for the X, Y and Z values - the canvas will tilt slightly.

We chose these values by adjusting them until we found the best effect. Using the manipulators is a good way to experiment with transforming objects.

Editing the rectangles

Next edit the rectangles:

  1. Select the rectangles.
  2. In the Inspector, set Flexibility for both height and width, so they scale proportionately with screen of the device.

The rectangles are too small for our effect. To adjust this:

  1. Go to Size in the Inspector.
  2. Set Width to 375 and Height to 617.

You'll now see a large rectangle in the scene:



At the moment, one rectangle is completely covering the other. To adjust this change the Position of:

  1. rect_frame to 34.3 on the X axis and 19.1 on the Y axis.
  2. rect_overlay to 36 on the X axis and 44.4 on the Y axis.

Change the Scale of:

  1. rect_frame to 1.2 on the X axis and 0.9 on the Y axis.
  2. rect_overlay to 1 on the X axis and 0.7 on the Y axis.

Creating materials

Create a material for each rectangle, by clicking the + next to Material in the Inspector.

Rename:

  1. The material you've made for rect_frame, frame_mat.
  2. The material you've made for rect_overlay, overlay_mat.

Editing the materials

The Shader Type should be Flat for both materials, because we don't need them to omit or respond to light. It's more performant than a standard shader, so it helps keep the size of the effect down.

For frame_mat:

  1. Go to Diffuse. Next to Texture, apply the texture frame_tex.
  2. Check the box for Alpha Test and adjust the Cutoff slider to make some semi-transparent parts of the texture transparent. We set it to 50%.


Now select overlay_mat. In the Inspector:

  1. Go to Render Options.
  2. Set Opacity to 30%, to create the semi-transparent effect.

The frame is taking shape now:



Overlay_mat changes color when the screen is tapped. You'll use the Patch Editor to do this. Start by clicking the arrow next to Texture in the Inspector to make a patch representing the Diffuse Texture property of the material.



We'll add the rest of the patches later.

Adding the dynamic text

The text in this effect is a dynamic text object. Dynamic text takes data from a user's device, like their location or the time, and represents it as text.

To add the dynamic text:

  1. Select dynamic_text in the Scene panel.
  2. In the Inspector, delete the text in the Text Box.
  3. Next to Dynamic Text, click Insert.
  4. Insert 2 dynamic text tokens from the menu - Current City and Date (Long).

There are lots of others types of dynamic text to choose from when creating your own effects.

Next change:

  1. Font to Facebook Script Light.
  2. Font Size to 40.
  3. Line Spacing to 3000.
  4. Position to 38 on the X axis and -172 on the Y axis.

You'll see the text is in the middle of the frame. To fix this, change the Size values. Click in each of the boxes and select Fill Width and Fill Height to make the text the same width as the canvas:



Next to Pinning, pin the text to the top, bottom and both sides of the canvas. Pinning the text will mean it always maintains the same distance from the canvas's border.

Adding interactivity and logic

Now we'll make the color of the frame change in response to a tap on the screen of the device.

You've already created the frame_color_mat patch. Create the other 3 patches by right-clicking anywhere in the Patch Editor, and choosing them from the menu. Select:

  1. A Screen Tap patch, to detect when the screen is tapped - you could use another interaction patch on the menu.
  2. A Counter patch.
  3. An Option Picker patch.

Adding the colors

You'll add the colors to the Option Picker. First change the Option Picker's data type to Color:

  1. Select the Option Picker.
  2. Select Color from the menu at the bottom of the patch.

To add the colors, click the squares in the Option Picker. Choose a color for each one from the menu:

Connecting the patches

Connect:

  1. The Tap output in the Screen Tap patch to the Increase input in the Counter patch.
  2. The output of the Counter patch to the Option input in the Option Picker.
  3. The Option Picker to the patch representing the material.


You can test the effect in the Simulator, by clicking the gear and selecting Simulate Touch:

Adding audio

To finish the effect, add a sound that plays each time the screen is tapped. This is known as 'one-shot' audio:

Something Went Wrong
We're having trouble playing this video.


It’s super easy, all you’ll do is add 4 more patches to your graph.

We’ve already added the audio file you’ll need to the project - it’s listed as arl_sfx_UITick_os_01.m4a in the Assets panel.

Add a speaker

To render sound in any effect, you’ll need a scene object called a speaker. To add it to the project:

  1. Click Add Object.
  2. Select Speaker from the menu.

The network of patches you’ll build will send a signal to a patch representing the speaker, playing the sound in the scene.

To create a patch for the speaker:

  1. In the Scene panel, select speaker0.
  2. Go to the Inspector.
  3. Click the arrow to the left of Audio.

A yellow patch will be added to the Patch Editor:

Adding the one-shot audio effect

To do this you’ll connect the Screen Tap patch to the speaker patch, using a Multi-Clip Controller patch and Audio Player patch to play this audio file through the speaker.

The Multi-Clip Controller patch can play the same sound multiple times, overlapping with previous playback instances. With longer audio clips, it’s worth experimenting with the Single-Clip Controller instead, which will stop the previous playback instance before playing a new one.

To create these patches, right-click in the Patch Editor to open the menu. Select the:

  • Multi-Clip Controller patch.
  • Audio Player patch.


You’ll also need a patch representing the audio file. To create it, just select arl_sfx_UITick_os_01.m4a in the Assets panel and drag it into the Patch Editor. An orange patch will be added:



Now connect the patches. Connect:

  1. The Tap output of the Screen Tap patch to the Play input in the Multi-Clip Controller patch.
  2. The output of the Multi-Clip Controller patch to the Controller input in the Audio Player patch.
  3. The output of the Audio Player patch to the Audio input in the yellow patch representing the speaker.
  4. The output of the orange patch representing the audio clip to the Audio Clip input in the Audio Player patch.

Here’s how the graph will look:



You’ve now added the audio clip to your effect! You can test it by clicking in the Simulator. You might need to click the Refresh button in the toolbar to hear it.

Tapping the screen in this effect is a subtle interaction, so the sound shouldn’t stand out too much. Complete the effect by adjusting the volume:

  1. In the Scene panel, select speaker0.
  2. Go to the Inspector.
  3. Change Volume to 50%, using the slider.

Learn more

Join the Spark AR Creator's community

Find inspiration, see examples, get support, and share your work with a network of creators.

Join Community

Join the Spark AR Creator's community

Find inspiration, see examples, get support, and share your work with a network of creators.

Join Community

Frequently asked questions

Have a specific question? Maybe it's been answered.


Read FAQs
Was this document helpful?