You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: scene-editor/script-node.rst
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ Script Nodes
6
6
7
7
.. toctree::
8
8
9
+
script-node-vs-user-component
9
10
script-node-create
10
11
script-node-class
11
12
script-node-basic-scripts-project
@@ -14,14 +15,14 @@ Script Nodes
14
15
15
16
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.
16
17
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.
18
19
19
20
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_.
20
21
21
22
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.
22
23
23
24
This allows expressing complex behaviors combining logical building blocks (|ScriptNode|_ prefabs) in a hierarchical structure.
24
25
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.
26
27
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