|
1 | | - |
2 | | - |
3 | 1 | <div class="header-banner pineapple"> |
4 | 2 | <div class="header-label pineapple">Layered Portraits</div> |
5 | 3 | </div> |
6 | 4 |
|
7 | | -*This page describes how to create layered portraits.* |
| 5 | +*This page describes how to create and use layered portrait scenes.* |
8 | 6 |
|
9 | 7 | ## 📜 Content |
| 8 | + |
10 | 9 | [toc] |
11 | 10 |
|
12 | 11 | ## 1. Introduction |
13 | 12 |
|
14 | | -If you want to have a character with multiple layers, like a body, a head, and |
15 | | -a mouth, you can use the **Layered Portrait** feature. |
16 | | - |
17 | | -Dialogic uses the concept of Godot scenes to create portraits. The layered portrait feature provides us with a GDScript that you can use for this purpose. |
18 | | - |
19 | | -If you are eager to learn more about the requirements for creating a custom portrait, please refer to the [Custom Portraits](custom-portraits.md) page. |
| 13 | +If you want to have a character with multiple layers, like a body, a head, and a mouth, you can use the custom **Layered Portrait** scene. This scene allows creating a character from many sprites and then allows showing, hiding and switching between these sprites **from the timeline!** |
20 | 14 |
|
| 15 | +If you are eager to learn more about how dialogic uses scenes to create portraits and the requirements for creating a custom portrait, please refer to the [Custom Portraits](custom-portraits.md) page. |
21 | 16 |
|
22 | 17 | ## 2. Rundown |
23 | 18 |
|
24 | | -You will learn to create a new character, add a new portrait, and then create a |
25 | | -new Godot scene for the custom scene of this portrait.\ |
26 | | -Finally, you will learn how to control the layers of the portrait using the |
27 | | -timeline. |
| 19 | +First, you will learn how to create a new layered portrait scene and set it up correctly. |
28 | 20 |
|
| 21 | +Finally, you will learn how to control the layers of the portrait using the timeline. |
29 | 22 |
|
30 | 23 | ## 2.1. Preparation |
31 | 24 |
|
32 | | -I will use a character named `Agustina`, if you want to follow along, you can download the assets from [https://dejinyucu.itch.io/agustina-visual-novel-sprite](https://dejinyucu.itch.io/agustina-visual-novel-sprite).\ |
33 | | -Heads up: The character is available as a PSD file; you will have to pick the |
34 | | -layers and export them as image files. |
35 | | - |
36 | | - |
37 | | -## 3. Creating a new Character |
38 | | - |
39 | | -First, head over to the Dialogic Character tab. You will need to create |
40 | | -yourself a new character or edit an existing one. |
41 | | - |
42 | | -Each character can have multiple portraits. You can add a new portrait or use |
43 | | -an existing one. |
44 | | - |
45 | | -Heading over to the last segment of the Character Editor, you will find the |
46 | | -preview and the **Portrait Settings**.\ |
47 | | -Unfold the **Scene** option, and you will see a file picker. We will head back |
48 | | -here once the scene file is done, set it. |
49 | | - |
50 | | - |
51 | | - |
52 | | - |
53 | | -## 4. Creating a Portrait Scene |
54 | | - |
55 | | -Now, we want to create a new scene in the **FileSystem** tab of Godot. |
56 | | -We recommend creating a new folder for your portrait scenes, so you can keep |
57 | | -your project organized. |
58 | | - |
59 | | -Right-click on the folder and hover **Create New**, and click **Scene...** on the |
60 | | -follow-up menu. |
| 25 | +I will use a character named `Agustina`, if you want to follow along, you can download the assets from [https://dejinyucu.itch.io/agustina-visual-novel-sprite](https://dejinyucu.itch.io/agustina-visual-novel-sprite). |
61 | 26 |
|
62 | | -Select the **Root Type**, we recommend using the **Node** option, selecting the |
63 | | - `CanvasGroup` type. |
| 27 | +*Heads up: The character is available as a PSD file; you will have to pick the layers and export them as image files.* |
64 | 28 |
|
65 | | -The `CanvasGroup` type allows Godot to treat all layers as a single image, |
66 | | -preventing the layers from fading in and out separately. |
| 29 | +You will also have to have a character. You can use an existing one or create a new one for this. On that character (in the Character Editor) add or select a portrait. |
67 | 30 |
|
68 | | -The **Scene Name** is up to you, but once again, we recommend keeping your |
69 | | -project organized with a consistent naming scheme. |
| 31 | +## 3. Creating the Base Layered Portrait Scene |
70 | 32 |
|
71 | | - |
| 33 | +In the Character Editors "Portrait Settings" section, head to the **Scene** section. |
72 | 34 |
|
73 | | -Once you press **OK**, your new scene will be opened in the **Scene** tab of |
74 | | -Godot. Switch to the **2D** tab in the upper-middle of Godot, and you will see |
75 | | -your new scene. |
| 35 | + |
76 | 36 |
|
77 | | - |
| 37 | +Click the little arrows icon to change the portrait scene. |
78 | 38 |
|
79 | | -## 4.1. Adding the Layered Portrait GDScript |
| 39 | +In the popup that opens select the `Layered Portrait` and then click `Customize This Scene`. |
80 | 40 |
|
81 | | -To use your scene as a layered portrait, we will add a built-in |
82 | | -GDScript to the root node of your scene. |
| 41 | + |
83 | 42 |
|
84 | | -Right-click on the root node and hover over **Attach Script**. |
| 43 | +This will promt you to save the new scene somewhere in the file system. Navigate to a place that makes sense in your file oranization and adjust the file name if necessary. Then click `Save`. |
85 | 44 |
|
86 | | - |
| 45 | +You can now open this scene with the little arrow icon button (or from the file system). |
87 | 46 |
|
88 | | -You can copy the following path and paste it into the **Path** field: |
| 47 | + |
89 | 48 |
|
90 | | -``` |
91 | | -res://addons/dialogic/Modules/Character/LayeredPortrait/layered_portrait.gd |
92 | | -``` |
93 | | - |
94 | | - |
95 | | - |
96 | | -Press **Load** and... that's it! You have now added the Layered Portrait |
97 | | -scripting logic; now onto the fun part! |
98 | | - |
99 | | -```admonish info |
100 | | -The script may open in the **Script** tab of Godot or an external editor, |
101 | | -feel free to ignore this and move back to the **2D** tab.\ |
102 | | -It's not recommended to edit this file without copying it to your own project's |
103 | | -folder. |
104 | | -``` |
105 | | - |
106 | | -## 4.2. Adding the Layers |
107 | | - |
108 | | -Your layered portrait can have multiple layers. We recommend using `Node2D` as |
109 | | -grouping layers, and `Sprite2D` as the actual layers. |
| 49 | +## 4. Filling the scene |
110 | 50 |
|
111 | | -There is no limitation what Node Types you use for your layers. |
| 51 | +At the beginning the scene will have only a few nodes to get you started: |
112 | 52 |
|
113 | | -This will require some manual work, but it gives you control over how the |
114 | | -layers are organized. The node paths will be used in the |
115 | | -**Layer Command Syntax**; we will cover this in a later section. |
| 53 | + |
116 | 54 |
|
| 55 | +You will usually have a "Base" layer, which should be the first Sprite we add. So we select the first Sprite, rename it to "Base", and drag our base texture into the inspectors `Texture` property. |
117 | 56 |
|
118 | | -Here is my scene structure: |
| 57 | +For anything you have "variations" of, in this case for example the Eyes, Eyebrows, Mouths and Clothes, you'll want to have a "Group", like the one that is already in the scene. A group will later allow us to easily switch between these variations. |
119 | 58 |
|
120 | | - |
| 59 | +By adding more Groups (Node2D) and Sprites (Sprite2D), naming them properly (we will use these later) and setting the textures, we will get something like this: |
121 | 60 |
|
122 | | -I left some of the layers hidden to define the default look of the portrait. |
| 61 | + |
123 | 62 |
|
124 | | -## 4.3. Setting the Layered Portrait Scene |
| 63 | +*Note: The Sprites of the Augustina example all fill the same rectangle. This means they are automatically all correctly positioned on top of each other. If your sprites cover different regions of the character, you might have to manually move them to be positioned correctly.* |
125 | 64 |
|
126 | | -Remember the file picker in the Character editor? Now is the time to use it! |
127 | | -Copy the path of your scene file and paste it into the file picker or navigate |
128 | | -to your scene file. |
129 | 65 |
|
130 | | - |
131 | 66 |
|
132 | | -Once you have selected your scene file, you should be able to see your portrait |
133 | | -in the Character Editor's Preview. |
| 67 | +Save the scene and head back to the character editor. If everything went right, you should now see your scene there: |
134 | 68 |
|
| 69 | + |
135 | 70 |
|
136 | | -## 5. Controlling the Layers |
| 71 | +Hurray! |
137 | 72 |
|
138 | | -As of right now, you can use the `Character` event to control the layers. |
139 | | -The functionality is limited to the `join` and `update` variants of this event. |
| 73 | +## 5. Controlling the Layers from the timeline |
140 | 74 |
|
141 | | -In Dialogic, this event accepts a parameter called `extra_data`. Using the Layer |
142 | | -Command Syntax, you can control the portraits from timelines using the |
143 | | -`extra_data`. |
| 75 | +You can control these layers from the character event (when joining or updating). Any communication with the portrait scene happens via the `extra_data` parameter, for example like this: |
144 | 76 |
|
145 | | -Take a look at this example: |
146 | 77 | ```tml |
147 | | -join agustina (Layered) 2 [animation="Heartbeat" extra_data="set Mouth/Smile"] |
| 78 | +join Agustina center [extra_data="set Mouth/Happy"] |
| 79 | +[wait_input] |
| 80 | +update Agustina [extra_data="set Eyes/Wink, set Mouth/Laugh, set Clothes/Outfit2"] |
148 | 81 | ``` |
149 | 82 |
|
| 83 | +In the visual editor you can use the same commands in the "Extra Data" field. |
| 84 | + |
150 | 85 | ## 5.1. Layer Command Syntax |
151 | 86 |
|
152 | 87 | Here is a list of valid commands you can use in the `extra_data` parameter: |
@@ -177,29 +112,12 @@ update agustina [extra_data="show Glasses/Normal, set Emote/Shock"] |
177 | 112 |
|
178 | 113 | # 6. FAQ |
179 | 114 |
|
180 | | -## 6.1. My Portrait is hovering above the Scene Ground |
181 | | - |
182 | | -Make sure all of your layers have the correct size. |
183 | | - |
184 | | -The Layered Portrait will use the size of all layers combined. If one layer is |
185 | | -extending further down than the others, it may appear floating above the ground |
186 | | -if the layer is not enabled. |
187 | | - |
188 | | -Try enabling all of your layers and select all nodes, you will be able to see |
189 | | -all boundaries in the editor window of your scene. |
190 | | - |
191 | | - |
192 | | -## 6.2 My Portrait's Position is heavily off |
193 | | - |
194 | | -If you use a `Control` (and comparable types), ensure that its position aligns |
195 | | -with the root's position. Otherwise, the overall coverage of your portrait |
196 | | -will be visually unpredictable in the editor. |
| 115 | +## 6.1. My Portrait's Position is wrong |
197 | 116 |
|
| 117 | +The layered portrait calculate the combined size of all the layers. If your layers have different sizes/positions, make sure no layer extends further then needed. Try enabling all of your layers and select all nodes, you will be able to see all boundaries in the editor window of your scene. |
198 | 118 |
|
199 | | -## 6.3 Do I have to use `CanvasGroup` as Root Node? |
| 119 | +By default the Layered Portraits scripts `fix_offset` parameter (in the inspector under Layered Portrait/Private/fix_offset) is on. This will adjust the position based on the first sprite on the assumption that it will be the base sprite. For many portraits that makes it easier, but for more granular control you can turn it off. In that case your sprites should be positioned so that the top-left corner of your character is at the scene origin! |
200 | 120 |
|
201 | | -No, but if you use any transitions on your layered sprite, the player will see |
202 | | -every single layer fading at once. |
| 121 | +## 6.2 Do I have to use `CanvasGroup` as Root Node? |
203 | 122 |
|
204 | | -If you have a Skin Layer covered mostly by a Dress Layer, you will see the Skin |
205 | | -and Dress layer fading in and out separately. |
| 123 | +No, but it's the best at handling transitions. |
0 commit comments