pull/2/head
jaysunxiao 2022-06-28 18:22:03 +08:00
parent 01837fc143
commit 320c3261fe
8 changed files with 77 additions and 10 deletions

View File

@ -1,10 +1,34 @@
# 组件的使用 # 1. Line2D 节点
- Path2D
- 在 2D 空间中通过几个点连成的线,可以通过代码动态添加和删除
```
注意默认情况下Godot一次最多只能绘制 4,096 个多边形点。
要增加这个限制,请打开项目设置,修改下面两个设置
ProjectSettings.rendering/limits/buffers/canvas_polygon_buffer_size_kb
ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb。
```
# 2. RemoteTransform2D 节点
- RemoteTransform2D类似与设计模式中的代理模式代理一个节点
```
RemoteTransform2D pushes its own Transform2D to another CanvasItem derived Node in the scene.
It can be set to update another Node's position, rotation and/or scale. It can use either global or local coordinates.
```
# 3. Path2D 节点
- Path2D包含了一个曲线路径数据
``` ```
Contains a Curve2D path for PathFollow2D nodes to followDescribes a Bézier curve in 2D space. Contains a Curve2D path for PathFollow2D nodes to followDescribes a Bézier curve in 2D space.
``` ```
- PathFollow2D - PathFollow2D要和Path2D结合在一起使用
``` ```
This node takes its parent Path2D, and returns the coordinates of a point within it, given a distance from the first vertex. This node takes its parent Path2D, and returns the coordinates of a point within it, given a distance from the first vertex.
@ -12,10 +36,3 @@ This node takes its parent Path2D, and returns the coordinates of a point within
It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be children of this node. It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be children of this node.
The descendant nodes will then move accordingly when setting an offset in this node. The descendant nodes will then move accordingly when setting an offset in this node.
``` ```
- RemoteTransform2D类似与设计模式中的代理模式
```
RemoteTransform2D pushes its own Transform2D to another CanvasItem derived Node in the scene.
It can be set to update another Node's position, rotation and/or scale. It can use either global or local coordinates.
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -0,0 +1,26 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://script/demo06_move/move_hero.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[ext_resource path="res://script/demo08_path/my_line.gd" type="Script" id=3]
[sub_resource type="Curve" id=1]
_data = [ Vector2( 0, 0.0545454 ), 0.0, 0.0, 0, 0, Vector2( 0.155556, 0.3 ), 0.0, 0.0, 0, 0, Vector2( 0.361111, 0.572727 ), 0.0, 0.0, 0, 0, Vector2( 0.733333, 0.781818 ), 0.0, 0.0, 0, 0, Vector2( 0.916667, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="Gradient" id=2]
offsets = PoolRealArray( 0, 0.395973, 1 )
colors = PoolColorArray( 0.133195, 0.308942, 0.362743, 1, 0.226219, 0.464389, 0.839305, 1, 0.0228882, 0.261307, 0.976563, 1 )
[node name="Node2D" type="Node2D"]
[node name="Line2D" type="Line2D" parent="."]
width = 64.0
width_curve = SubResource( 1 )
default_color = Color( 0.4, 0.501961, 1, 1 )
gradient = SubResource( 2 )
script = ExtResource( 3 )
[node name="Player" type="Sprite" parent="."]
position = Vector2( 159.521, 163.844 )
texture = ExtResource( 2 )
script = ExtResource( 1 )

View File

@ -0,0 +1,24 @@
extends Line2D
func _ready():
#add_point(Vector2(100, 100))
#add_point(Vector2(100, 200))
#add_point(Vector2(200, 200))
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var player = get_parent().find_node("Player")
var position = player.position
add_point(position)
if (get_point_count() >= 20):
remove_point(0)
pass
func pointTest():
add_point(Vector2(100, 100))
add_point(Vector2(100, 200))
add_point(Vector2(200, 200))
pass