Skip to content

Commit bc15f9f

Browse files
Adds Script Nodes vs User Components chapter.
1 parent 6ee1a05 commit bc15f9f

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"workbench.colorTheme": "Solarized Dark",
77
"cSpell.words": [
88
"tilemap",
9+
"toctree",
910
"toolkits"
1011
],
1112
"restructuredtext.confPath": "${workspaceFolder}",

CHANGELOG.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Updates Depth commands.
1010
* Updates prefab instance dynamic sections.
1111
* Updates chapters with new user component dynamic sections.
12+
* New chapter Script Nodes vs User Components.
1213

1314
## v3.61.0 - May 18, 2022
1415

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
.. include:: ../_header.rst
3+
4+
Script Nodes vs User Components
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
Now you have two mechanisms for assigning behaviors to an object: the |ScriptNode|_ and the |UserComponents|_. Now you have to decide when to use one or another. In this chapter, we try to provide you with a small guide.
8+
9+
**When to use a User Component?**
10+
11+
Many users find a user component very handy because you can edit its properties right away, in the same place as the object's properties. You don't need to browse an object's tree of nodes. Also, components are familiar philosophy in the Phaser API. However, user components have a main restriction: it has a one-to-one relationship with the object. It means, you can assign only a single type of component to the object, so it should implement the whole behavior as a unit.
12+
13+
These are some examples of modeling behaviors with user components:
14+
15+
* An **AutoplayAnimation** user component that you can add to sprites. It has an **animationKey** property that is played automatically. Because you can play only one animation at a time in a sprite, it fits well in the one-to-one relationship constraint of user components.
16+
* A **BorderAnchor** component, with a **anchorTo** property with values like ``left``, ``top``, ``right``, ``bottom``. This component will auto re-position the object in a responsive scene. Because an object has only one position, it fits in the one-to-one restriction of user components.
17+
18+
**When to use a Script Node?**
19+
20+
The script nodes are logical game objects and you can make prefabs of them. The prefabs system in the editor is powerful and you can express complex behaviors in a hierarchical relationship. Also, you can add script nodes not only to objects else to scenes too. However, it is very easy that you start abusing the use of script nodes and making large hierarchies of logical nodes. We think for now it isn't a good idea, but in the end, it is up to you.
21+
22+
Some examples of modeling behaviors with script nodes:
23+
24+
* When you can make logical units that you can combine and make different behaviors. For example, you can make a **StartSceneAction** script node with a **sceneKey** property. This node will start the **sceneKey** scene when it is executed. You can use this script in different contexts:
25+
* In a hierarchy of nodes for starting the Game scene after pressing a **Play** button.
26+
* You can use the same **StartSceneAction** in a hierarchy of nodes that listens to the SPACE key, so it starts the Game scene.
27+
* A **LevelGameplay** script node with the gameplay of a level. You can add this node to a different scene and changes the parameters of the gameplay, for making it harder.
28+
* A **PlayerCollider**, **DestroyObjectAction**, and a **ChangeHealthAction** scripts. You can combine them for expressing when a player hits an object in the level if it will destroy the object and how much it affects the player's health. You can create different combinations for the different kinds of objects in the level.
29+
30+
As we said previously, it is up to you when to use the script nodes and how much you split the behaviors in a tree of small logical units. Our advice is to keep it simple and learn first from your game before making a complex framework of script nodes.

scene-editor/script-node.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Script Nodes
66

77
.. toctree::
88

9+
script-node-vs-user-component
910
script-node-create
1011
script-node-class
1112
script-node-basic-scripts-project
@@ -14,14 +15,14 @@ Script Nodes
1415

1516
A |ScriptNode|_ is a new type of object. It isn't a display object, else a logical object you can use with different purposes, especially, for expressing simple and complex behaviors.
1617

17-
Until now, |UserComponents|_ were the way you had to add extra funcitonality to a game object. The |ScriptNode|_ is a more powerful and general tool, that you can use with the same purpose.
18+
Until now, |UserComponents|_ were the only way you had to add extra functionality to a game object. The |ScriptNode|_ is a more powerful and general tool, that you can use with the same purpose.
1819

1920
Basically, a |ScriptNode|_ is a logical object you can add to an scene, a game object, or another |ScriptNode|_. But what is even more exciting, is that you can make reusable and extensible |ScriptNodes|_ in the same way you make reusable and extensible game objects: using prefabs_.
2021

2122
This means, you can make a prefab of a |ScriptNode|_, add custom properties, create variants of the prefab, create nested prefabs, and append |ScriptNodes|_ to prefab instances.
2223

2324
This allows expressing complex behaviors combining logical building blocks (|ScriptNode|_ prefabs) in a hierarchical structure.
2425

25-
This concept of |ScriptNodes|_ is inspired by the `visual programming languages <https://en.wikipedia.org/wiki/Visual_programming_language>`_ and concepts like the `behavior tree <https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)>`_. However, we don't pretend to create a complete, full-featured, visual language. Our advice is using the |ScriptNodes|_ for making the blocks of repeated behaviors in your game. You can use it for dealing with the UI interface, menu screens, intro screens. You can use it in your gameplay, but not by combining a lot of general-purpose blocks, else by combining blocks you did especifically for your gameplay.
26+
This concept of |ScriptNodes|_ is inspired by the `visual programming languages <https://en.wikipedia.org/wiki/Visual_programming_language>`_ and concepts like the `behavior tree <https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)>`_. However, we don't pretend to create a complete, full-featured, visual language. Our advice is using the |ScriptNodes|_ for making the blocks of repeated behaviors in your game. You can use it for dealing with the UI interface, menu screens, intro screens. You can use it in your gameplay, but not by combining a lot of general-purpose blocks, else by combining blocks you did specifically for your gameplay.
2627

27-
An argument about the advantage of using a visual scripting language is that creators with no traditional programming experience can make a game. But our concept with the |ScriptNodes|_, is that you, the JavaScript programmer, can implement the script nodes "framework" for your game, and deliver it to the game level designer for connecting the scripts with the game objects and scenes. A good start could be the `script-nodes-basic <http://github.com/PhaserEditor2D/script-nodes-basic>`_ project.
28+
An argument about the advantage of using a visual scripting language is that creators with no traditional programming experience can make a game. But our concept with the |ScriptNodes|_, is that you, the JavaScript programmer, can implement the script nodes "framework" for your game, and deliver it to the game level designer for connecting the scripts with the game objects and scenes. A good start could be the `script-nodes-basic <http://github.com/PhaserEditor2D/script-nodes-basic>`_ project.

0 commit comments

Comments
 (0)