|
1 | 1 | # Scene Assets
|
2 | 2 |
|
3 |
| -In __Cocos Creator__, the __Scene__ is the cornerstone for organizing game content during development, and presenting all game content to the players. The __Scene__ itself is a file, also considered a game asset, and saves most of the game's information. |
| 3 | +In **Cocos Creator**, the **Scene** is the cornerstone for organizing game content during development, and presenting all game content to the players. The **Scene** itself is a file, also considered a game asset, and saves most of the game's information. |
| 4 | + |
| 5 | +> **Note**: please avoid multiple people modifying the same scene asset at the same time, as this may lead to conflicts that cannot be resolved by `git` merging. |
4 | 6 |
|
5 | 7 | ## Creating a Scene
|
6 | 8 |
|
7 |
| -There are __three__ ways to create a __Scene__: |
| 9 | +There are **three** ways to create a **Scene**: |
| 10 | + |
| 11 | +1. Select the folder to create the **Scene** file in the **Assets** panel. On the folder right-click and select **Create -> Scene**, and then type the desired **Scene** name. |
8 | 12 |
|
9 |
| -1. Select the folder where you want to create the __Scene__ file in the __Assets__. On the folder __Right click --> New --> Scene file__, and then type the desired __Scene__ name. |
10 | 13 |
|
11 | 14 | 
|
12 | 15 |
|
13 |
| - In order to have a good directory structure in your project, it is strongly recommend that you use this method to create a __Scene__. |
| 16 | + In order to have a good directory structure in the project, it is strongly recommended that use this method to create a **Scene**. |
| 17 | + |
14 | 18 |
|
15 |
| -2. Click the __Create__ menu in the __Assets__ to create a new __Scene__. |
| 19 | +2. Click the **Create (+)** button in the upper left corner of the **Assets** panel, and then select **Scene**. |
16 | 20 |
|
17 | 21 | 
|
18 | 22 |
|
19 |
| -3. Select __File -> New Scene__, a new __Scene__ will appear directly in the __Hierarchy__ panel, but a new __Scene__ will not appear in the __Assets__. You need to save it in the root of the asset folder. A `New Scene.scene` __Scene__ file appears in the directory. |
| 23 | +3. Select **File -> New Scene** in the top menu bar, a new scene will be created directly in the **Scene** panel. But the new scene file will not appear in the **Assets** panel, it is required to save the scene file manually in the **Save Scene** window that pops up when saving the scene, and the `scene.scene` file will appear in the root directory of the **Assets** panel only after the saving is done. |
| 24 | + |
20 | 25 |
|
21 | 26 | 
|
22 | 27 |
|
23 | 28 | ## Saving a Scene
|
24 | 29 |
|
25 |
| -While creating __Scenes__, you can quickly save __Scenes__ with the shortcut keys __Ctrl + S__ (Windows) or __Command + S__ (Mac). |
| 30 | +Method 1: Use the shortcut keys <kbd>Ctrl</kbd> + <kbd>S</kbd> (Windows) or <kbd>Command</kbd> + <kbd>S</kbd> (MacOS) to quickly save the scene. |
26 | 31 |
|
27 |
| -## Switching Scenes |
| 32 | +Method 2: Select **File -> Save Scene** in the top menu bar. |
28 | 33 |
|
29 |
| -In the __Assets__, __double-click__ the __Scene__ you want to open. When needing to switch __Scenes__ in the game, use the `director.loadScene()` API to implement dynamic scene loading and switching in the game. For further details, please see the [API documentation](__APIDOC__/en/classes/core.director-2.html#loadscene). |
| 34 | +## Switching Scenes |
30 | 35 |
|
31 |
| -## Scene Asset Properties |
| 36 | +In the **Assets** panel, **double-click** the **Scene** to be opened.<br> |
| 37 | +When needing to switch **Scenes** in the game, use the [director.loadScene()](__APIDOC__/en/classes/core.director-2.html#loadscene) API to implement dynamic scene loading and switching in the game. |
32 | 38 |
|
33 |
| -Since the __Scene__ is an __Asset__ a property can be set in the __Assets__ to load assets asynchronously. |
| 39 | +## Scene Properties |
34 | 40 |
|
35 |
| - |
| 41 | +After double-clicking to open the **scene** file, the `scene` is the root node of the scene node tree in the **Hierarchy** panel. Select the `scene` node, and set whether the scene is automatically released or not in the **Inspector** panel, as well as the whole scene related properties, including **ambient light** settings, **shadows** settings, **global fog** and **sky box** settings. |
36 | 42 |
|
37 |
| -After opening the __Scene__ file, **Scene** is the root node of the __Scene__ node tree. Select the __Scene__ node in the __Hierarchy__ panel. In the __Inspector__ panel on the left, you can set the properties of the entire __Scene__, including **ambient light** settings, **shadow** settings and **sky box** settings. |
| 43 | + |
38 | 44 |
|
39 |
| - |
| 45 | +Automatic release of scene assets, please refer to section **Change the policy of auto releasing assets from previous scene** below for details. |
40 | 46 |
|
41 |
| -For a detailed description of each property, see the following documents: |
| 47 | +For a detailed description of each property, see the following documentations: |
42 | 48 |
|
43 | 49 | - [Ambient light](../concepts/scene/light/lightType/ambient.md)
|
44 | 50 | - [Shadow](../concepts/scene/light/shadow.md)
|
45 | 51 | - [Global Fog](../concepts/scene/fog.md)
|
46 | 52 | - [Skybox](../concepts/scene/skybox.md)
|
| 53 | + |
| 54 | +## Change the Policy of Auto Releasing Assets from Previous Scene |
| 55 | + |
| 56 | +In a large game where there are many scenes, as the engine continues to load different scenes, the memory usage will continue to increase. Besides using API such as `assetManager.releaseAsset` to accurately release unused assets, one can also use scene's auto releasing feature. |
| 57 | + |
| 58 | + |
| 59 | +After double-clicking to open the scene file, select the `scene` node in the **Hierarchy** panel to set whether the scene is automatically released in the **Inspector** panel: |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +When switching from current scene to the next scene, if current scene disabled the auto releasing, then all assets (directly or indirectly) referenced by current scene (except loaded dynamically in scripts) will not release by default. On the other hand, if enable the auto releasing, then these assets will release by default. |
| 64 | + |
| 65 | +### Prevent auto releasing for some specified assets |
| 66 | + |
| 67 | +With the auto releasing enabled for a scene, if some of the scene's assets are saved in the script as "special reference", these references will become invalid once the scene switched, since the asset has been released, may cause rendering problems. To prevent these assets from being released automatically, we can use [Asset.addRef](__APIDOC__/en/classes/asset.asset-1.html#addref) to retain them. |
| 68 | + |
| 69 | +> "Special reference" refer to references in the form of global variables, singleton, closures, "dynamic assets", and so on.<br> |
| 70 | +> "Dynamic assets" refer to assets that are dynamically created or dynamically modified in a script. |
| 71 | +
|
| 72 | +The above content of the automatic release of scene assets can be summed up in the following diagram of several cases: |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +For additional information on asset release, please refer to the [Release of Assets](./release-manager.md#auto-release) documentation. |
0 commit comments