diff --git a/doc/demo08_path/path.md b/doc/demo08_path/path.md index 67668ba..7c56434 100644 --- a/doc/demo08_path/path.md +++ b/doc/demo08_path/path.md @@ -1,10 +1,34 @@ -# 组件的使用 -- Path2D +# 1. Line2D 节点 + +- 在 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 follow,Describes 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. @@ -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. 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. -``` diff --git a/scene/demo08_path/image/Godette.png b/scene/demo08_path/image/Godette.png new file mode 100644 index 0000000..c58f370 Binary files /dev/null and b/scene/demo08_path/image/Godette.png differ diff --git a/scene/demo08_path/image/Grasslands.png b/scene/demo08_path/image/Grasslands.png new file mode 100644 index 0000000..74b28d1 Binary files /dev/null and b/scene/demo08_path/image/Grasslands.png differ diff --git a/scene/demo08_path/image/Interactive.png b/scene/demo08_path/image/Interactive.png new file mode 100644 index 0000000..532d9ac Binary files /dev/null and b/scene/demo08_path/image/Interactive.png differ diff --git a/scene/demo08_path/image/Robi.png b/scene/demo08_path/image/Robi.png new file mode 100644 index 0000000..1d4e79c Binary files /dev/null and b/scene/demo08_path/image/Robi.png differ diff --git a/scene/demo08_path/image/Shadow.png b/scene/demo08_path/image/Shadow.png new file mode 100644 index 0000000..2f0a03a Binary files /dev/null and b/scene/demo08_path/image/Shadow.png differ diff --git a/scene/demo08_path/line.tscn b/scene/demo08_path/line.tscn new file mode 100644 index 0000000..3c4a464 --- /dev/null +++ b/scene/demo08_path/line.tscn @@ -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 ) diff --git a/script/demo08_path/my_line.gd b/script/demo08_path/my_line.gd new file mode 100644 index 0000000..6280732 --- /dev/null +++ b/script/demo08_path/my_line.gd @@ -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