Simple Timer Spark AR Patch Asset

Simple Timer: Spark AR Tutorial

How to create a simple timer in Spark AR Studio

There are lots of options for keeping track of time and counting things in Spark AR. I’m going to cover a few in this article and promote a patch asset I created called Simple Timer.


Runtime

Runtime Timer Spark AR
Runtime Timer Spark AR

From the Spark AR website: “The Runtime patch tracks the number of seconds that have passed since your effect started to run.”

This is a useful object as it is very specific and gives your effect a context in time. You can use it to show instructions during the first few seconds of opening the effect; as outlined in the link above.

If you combine Runtime with Offset, you can reset the difference—like zeroing out a scale. Any pulse to the Reset will reset the time sent to the output. This number has many digits after the decimal point. To round to the nearest whole number use Round. In combination with the Minimum object, which gives us the lesser of the two values, we can make the timer stop at 10; or any value you specify.

Counter

Tap to Increase Count Counter Spark AR
Tap to Increase Count Counter Spark AR

Counter is an object that does exactly what it says it will do: count. Pulses to the Increase or Decrease will do just that and output a whole number. In this patch screenshot, a Screen Tap pulse is increasing the Counter. If the number output Equals Exactly 5, a boolean signal triggers a change in the particle emitter system; a pink confetti celebration.

Jump is used to reset the counter to the value specified in the Jump to Number. The Maximum Count value will always be 1 greater than the biggest output number; which means if you want to count to 5, the Maximum Count should be 6.

If the counter reaches it’s maximum, it will restart counting from 0—it will not Jump to the Jump to Number value. In order to Jump to that number and begin counting from there, it needs to get an explicit pulse to the Jump input.

Animation & Loop Animation

Stop Counter At Number Spark AR
Stop Counter At Number Spark AR

Animation objects can also be used to set timer events. The “Animation” object does not output a count, but it does send out a progress value that is normalized from 0-1; if you are setting a timer for 5 seconds, it will send a progress value that is stretched from 0-1 over those five seconds. The other output is a “Completed” pulse, which can let other objects know when 5 seconds has passed. If you don’t need the timer count value, this is a great simple solution for triggering events.

Loop Animation is a useful object for driving a Counter. It sends out a pulse every time (x) “Duration” has passed. The lower Duration, the faster the pulse outputs. 1 equals 1 second. 0.5 equals 0.5 seconds.

In the example above, the Screen Tap will start the timer. After 5 seconds, the Counter will stop counting and a Particle Emitter system will be triggered to show confetti. The “Completed” pulse is used to shut the timer off in this case.

Simple Timer Patch Asset

Simple Timer Spark AR Patch Asset
Simple Timer Spark AR Patch Asset

Simple Timer is a patch asset I created to make complex timer events simple. If the Counter object and Loop Animation object had a baby, this would be it. It is flexible and makes timer state management easy.

Inputs

  • Start Pulse: Starts timer
  • Stop Pulse: Pauses timer
  • Reset Pulse: Restarts timer
  • Count Up: Counts up to the Stop Time
  • Count Down: Counts down to the Stop Time
  • Speed: 1 = count every 1 second, 10 = count every 0.1 seconds, 100 = count every 0.01 seconds…
  • Start Time: Timer start value
  • Stop Time: Timer end value

Outputs

  • Time: Scalar Value = Current Time
  • Done: Boolean = True when Timer reaches Stop Time
  • Timer On: Boolean = True when Timer is running.

Simple Timer YouTube Tutorial

2 thoughts on “Simple Timer: Spark AR Tutorial”

  1. I use your simple timer patch, when I first time stop the timer, it will reset the timer as well, but after first round stopping the timer, it works. How to fix the first time issue? I would like to stop timer and not reset the timer in the first round

Leave a Comment