Effect Maker从零构建互动测验:视觉脚本与计分逻辑
Effect Maker Tutorial: Gaming 101 with @cloves_ar
独立开发者或创作者可直接照做,用视觉脚本快速搭建互动滤镜或小游戏,无需写代码即可掌握计分与状态管理逻辑。
Hi, it's Claus again and in this tutorial I will show you how to build a fully interactive quiz from scratch inside effect maker. No template, just pure visual scripting. By the end, we will have a three question game that grades your choices and reveals your pet vibe. Are you more of a cat or a [music] dog? Before we start building, let's take a look on how the game works behind the scenes. Understanding the logic first will make the visual script much easier to follow later.
嗨,我是 Claus 又来了。在本教程中,我将向你展示如何在 Effect Maker 中从零开始构建一个完全互动的测验游戏。没有模板,只有纯粹的可视化脚本。最终,我们将拥有一个包含三个问题的游戏,它会根据你的选择进行评分并揭示你的宠物氛围:你更像猫还是像[音乐]狗?在开始构建之前,让我们先看看游戏背后的工作原理。首先理解逻辑会让后续的可视化脚本更容易跟上。
The quiz is based on a very simple scoring system. Every choice the player makes changes a single score value. If the player choose the option on the left, we add one point. If they choose the option on the right, we subtract one point. After all three questions, the script checks the final score. If this score is below zero, the result is cat. And if the score is above zero, the result is dog. Since our quiz has three questions, the final score can never be zero.
这个测验基于一个非常简单的计分系统。玩家做出的每个选择都会改变一个单一的分数值。如果玩家选择左边的选项,我们加一分;如果选择右边的选项,我们减一分。在所有三个问题结束后,脚本会检查最终分数。如果分数低于零,结果是“猫”;如果分数高于零,结果是“狗”。由于我们的测验有三个问题,最终分数永远不会是零。
Okay, so now that you understand how the logic works, let's move on to the fun part, building it from scratch. If you're not comfortable with variables and lists yet, I'd totally recommend watching our visual scripting 101 and 102 tutorials first. Otherwise, let's get started. From the effect maker home screen, create a new project. We'll start by building the basic layout for our quiz, including the question text and the two short choices.
好的,既然你已经理解了逻辑是如何工作的,让我们进入有趣的部分——从零开始构建它。如果你还不太熟悉变量和列表,我强烈建议你先观看我们的可视化脚本入门教程(101 和 102)。否则,我们开始吧。从 Effect Maker 的主屏幕创建一个新项目。我们将首先为测验构建基本布局,包括问题和两个简短的选项。
Open the text menu and add a new text object. I'll move it to the top of the screen and quickly adjust the font size and colors to make it look a little nicer. I already type in our first question. We can move. Now, let's rename this object to question to keep our scene organized. A clean hierarchy makes your project much easier to manage as it grows. Next, let's add the two image that will represent each choice. Open the image menu and create a new image.
打开文本菜单并添加一个新的文本对象。我会把它移到屏幕顶部,并快速调整字体大小和颜色,使其看起来更美观。我已经输入了第一个问题。我们可以移动它了。现在,让我们将这个对象重命名为 question(问题),以保持场景的整洁。清晰的层级结构会使项目随着增长而更容易管理。接下来,让我们添加代表每个选项的两个图像。打开图像菜单并创建一个新的图像。
Then duplicate it by right-clicking the object and selecting duplicate. For the second image, simply use the same X position with the opposite value. This keeps both choices perfectly centered on the screen. Finally, rename them to choice A and choice B. Great. Our base layout is now ready and we can start making it interactive. Now let's open the visual script. Click this icon change layout. Then select show visa script.
然后通过右键单击对象并选择“重复”来复制它。对于第二个图像,只需使用相同的 X 坐标但取相反的值。这样可以让两个选项在屏幕上完美居中。最后,将它们重命名为 choice A 和 choice B。太好了。我们的基础布局现在已经准备好,我们可以开始让它变得可交互了。现在让我们打开可视化脚本。点击这个图标更改布局,然后选择显示可视化脚本。
Next, head over to the variables panel and create a new variable. This will be our questions list. Set the type to text and the value type to list of values. I'll set the first one to weekend mood. Then click add to insert two more. Which move genre do you prefer? And what's your favorite weather? Great. Now let's go back to the variables panel and create another list. This one will store the image for our left side the dog vibe.
接下来,前往变量面板并创建一个新变量。这将作为我们的问题列表。将类型设置为文本,值类型设置为值列表。我将第一个设置为周末心情。然后点击添加以插入另外两个。你更喜欢哪种流派?以及你最喜欢的天气是什么?很好。现在让我们回到变量面板并创建另一个列表。这个列表将存储我们左侧狗狗氛围的图片。
So I will rename it to dog choices. Set the type to asset and the value type to list. Splitting our image into two separated lists. One for the dog interest and one for catchers keeps the logic much simpler down the line. So I will create another list for catch choices. For this tutorial, I created the graphics in Photoshop, but you can use any design software do you prefer. Each question has two possible answers. So, we'll need two images per question, one representing the dog vibe and the other representing the cat vibe.
所以我会将其重命名为狗狗选择。将类型设置为资产,值类型设置为列表。将图片分成两个独立的列表。一个用于狗狗兴趣,另一个用于猫咪选择,这样在后续的逻辑处理中会简单得多。因此,我将为猫咪选择创建另一个列表。在本教程中,我在 Photoshop 中创建了图形,但你也可以使用任何设计软件。每个问题有两个可能的答案。因此,我们需要每个问题两张图片,一张代表狗狗氛围,另一张代表猫咪氛围。
I will keep all of the dog choices on the left and all of the cat choice on the right. I've already exported mine. Try to keep them the same size and only as large as they need to be. The smaller assets help keeps your effect running smoothly. Now in effect maker, open the assets panel, click upload asset and import all six images into your project. Now that the images are in the project, let's populate our list. Open the dog choices and assign the three dog images in order.
我会将所有狗狗选择放在左侧,所有猫咪选择放在右侧。我已经导出了我的图片。尽量保持它们大小相同,并且只尽可能大。较小的资产有助于让你的效果运行更流畅。现在在 Effect Maker 中,打开资产面板,点击上传资产并将所有六张图片导入到你的项目中。既然图片已经在项目中,让我们填充我们的列表。打开狗狗选择并按顺序分配三张狗狗图片。
Then do the same for cat choices with the three cat images. Let's take this moment to put the first image from each list onto choice A and choice B so they don't start out blank. Now it's time to start building the large behind our game. Click add interaction and you will see all the different nodes we can use to build our visor script. Let's start by changing one of the objects in our scene. Search for a set property and add it to the graph.
然后对猫咪选择做同样的操作,使用三张猫咪图片。让我们利用这个机会将每个列表中的第一张图片放到选项 A 和选项 B 上,这样它们就不会一开始就是空白的。现在是时候开始构建我们游戏背后的逻辑了。点击添加交互,你将看到我们可以用来构建 Visor 脚本的所有不同节点。让我们从更改场景中的一个对象开始。搜索设置属性并将其添加到图中。
This is one of the most useful nodes in effect maker because it lets us change almost any property of an object while the effect is running. In our case, we'll use it to change the assets of choice age, allowing us to swap its image during the game. Now, we need something to trigger that change. Since this game is controlled by head movement, we'll use the head gesture node and set the gesture to ch left. Every time the player tilts their head, this node sends a sino through the graph and starts the rest of the logic.
这是 Effect Maker 中最有用的节点之一,因为它允许我们在效果运行时更改对象的几乎任何属性。在我们的案例中,我们将用它来更改选项 A 的资产,从而允许我们在游戏过程中交换其图片。现在,我们需要一些东西来触发这种变化。由于这个游戏是由头部运动控制的,我们将使用头部手势节点并将手势设置为向左倾斜。每当玩家倾斜头部时,这个节点就会通过图发送信号并开始其余的逻辑。
And you can think of that sino as a water flowing through a river, activating each node along the way. Whenever you want to add a new node, you can also right click anywhere in an empty area of the graph and just search for it. It's usually much faster than browsing through the menu. So now connect the output of head gesture to set property. At this point, every left head tilt will trigger the node. That works, but it isn't very practical.
你可以将 sino 想象成一条河流中的水流,沿途激活每个节点。每当你要添加新节点时,也可以在图形的空白区域右键单击并直接搜索。这通常比浏览菜单快得多。现在,将头部姿态的输出连接到 set property(设置属性)节点。此时,每次向左倾斜头部都会触发该节点。这样可以工作,但实用性不高。
While you're building the project, we'd have to tilt our heads every single time we wanted to test a small change. So, instead of tilting our heads every time, we will temporarily replace the head gesture node with a object dependent trigger to depart. Then assign choice A as the target object. Connect it exactly where the head gesture node was connected before. This way clicking the image in repro simulates selecting that answer making it much faster to build and debug the rest of the project.
在构建项目时,如果我们要测试微小的更改,就得每次都歪头。因此,与其每次都歪头,我们将暂时用 object dependent trigger to depart(对象依赖触发器)替换头部姿态节点。然后将 choice A(选项 A)指定为目标对象。将其连接的位置与之前头部姿态节点的连接位置完全相同。这样,在 repro 中点击图像即可模拟选择该答案,从而更快地构建和调试项目的其余部分。
You can just go ahead and give it a try. Before we animate anything, let's create two variables that we'll use in the project. The first one is score. We'll use it later to determine a player's final result. the second round, which keeps track of which question the player is currently on. Get the score variable into the graph. Search for the ad node and set its value to one. Then connect the result back to a score variable.
你可以直接尝试一下。在制作任何动画之前,让我们创建两个将在项目中使用的变量。第一个是 score(分数),我们稍后会用它来确定玩家的最终结果。第二个是 round(轮次),用于跟踪玩家当前所在的题目。将 score 变量引入图中。搜索 ad 节点并将其值设置为 1。然后将结果连接回 score 变量。
And now, every time this interaction run, the score increases by one. With the scoring logic in place, let's make the interaction feel a little nicer. Whenever the player selects an answer, we want the image to briefly grow and then returns to its original size. Small animations like this make the effect feel much more responsive. Search for transition and add it to the graph. We'll use together with another set property node.
现在,每次此交互运行时,分数都会增加 1。有了计分逻辑后,让我们让交互体验稍微好一点。每当玩家选择一个答案时,我们希望图像短暂放大,然后恢复原始大小。像这样的小动画能让效果显得更加响应迅速。搜索 transition(过渡)并将其添加到图中。我们将它与另一个 set property(设置属性)节点一起使用。
This time instead of changing the asset, we'll change its size. Connect the outputs of our score logic to the transition node. If we look at the inspector, we can see that our image is currently 230x 230 pixels. Let's animate it from 230 to 260 over half a second. Now connect the output on change of the transition node to the size property. Okay, so we got an error. It says value and size must be the same data type. This happens because the size property actually expects two values, width and height.
这次我们不更改资产,而是更改其大小。将我们的计分逻辑输出连接到 transition(过渡)节点。如果我们查看检查器(inspector),可以看到当前图像尺寸为 230x230 像素。让我们在半秒内将其从 230 动画到 260。现在,将 transition 节点的 on change(更改时)输出连接到 size(尺寸)属性。好的,出现了一个错误。它提示 value(值)和 size(尺寸)必须是相同的数据类型。这是因为 size 属性实际上需要两个值:宽度和高度。
A single number isn't enough. To fix that, search for the combine into vector node. Connect it between the transition and set property nodes and try again. Yeah, much better. Now, now duplicate both transition nodes. Select and press control D or command D to duplicate. For the second one, simply reverse the values. Connect it so it starts when the first transition finishes. Then make the animation a little smoother by setting the first transition curve to is out and the second one to is in.
单个数值是不够的。为了解决这个问题,请搜索“合并到向量”节点。将其连接在过渡节点和设置属性节点之间,然后重试。嗯,好多了。现在,复制两个过渡节点。选中并按下 Control+D 或 Command+D 进行复制。对于第二个节点,只需将值反转。连接它们,使其在第一个过渡完成后开始。然后通过设置第一个过渡曲线为“缓出”,第二个过渡曲线为“缓入”,使动画更加平滑。
So now let's test it again. Okay, but there is still one small problem. While the animation is playing, the player could select the same option multiple times, restarting the animation and triggering the rest of our logic more than once. To prevent that, we are going to create a simple gate. For this, create a new boolean variable called is animation. When the first transition starts, set is animation to true. Then duplicate that node, connect it to the end of the second trans
所以现在让我们再次测试一下。好的,但仍然存在一个小问题。在动画播放期间,玩家可能会多次选择同一个选项,从而重新启动动画并多次触发我们其余的逻辑。为了防止这种情况,我们将创建一个简单的门控逻辑。为此,创建一个新的布尔变量,命名为 isAnimation。当第一个过渡开始时,将 isAnimation 设置为 true。然后复制该节点,将其连接到第二个过渡的末尾
原文超出正文长度上限,此处截断——上游还有内容,完整版见上方「原文 ↗」。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力