diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..bb93750 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dwduwy3y2vipi" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..540f258 --- /dev/null +++ b/project.godot @@ -0,0 +1,42 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="godot-start" +config/features=PackedStringArray("4.2", "Forward Plus") +config/icon="res://icon.svg" + +[input] + +move_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} diff --git a/scene/demo01_hello/CustomNode.tscn b/scene/demo01_hello/CustomNode.tscn new file mode 100644 index 0000000..633e958 --- /dev/null +++ b/scene/demo01_hello/CustomNode.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://xl6nmhnrybxt"] + +[ext_resource type="Script" path="res://scene/demo01_hello/script/CustomNode.gd" id="1_eg1cy"] + +[node name="CustomNode" type="Node2D"] +script = ExtResource("1_eg1cy") diff --git a/scene/demo01_hello/HelloWorld.tscn b/scene/demo01_hello/HelloWorld.tscn new file mode 100644 index 0000000..dbde1a7 --- /dev/null +++ b/scene/demo01_hello/HelloWorld.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=2 format=3 uid="uid://dip07sfdhauy3"] + +[ext_resource type="Script" path="res://scene/demo01_hello/script/HelloWorld.gd" id="1_2stq7"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_2stq7") + +[node name="Label" type="Label" parent="."] +offset_left = 284.0 +offset_top = 138.0 +offset_right = 534.0 +offset_bottom = 248.0 +text = "Hello World!!!" diff --git a/scene/demo01_hello/NodeTest.tscn b/scene/demo01_hello/NodeTest.tscn new file mode 100644 index 0000000..49046e0 --- /dev/null +++ b/scene/demo01_hello/NodeTest.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://bfwao1wrksjvi"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="1_rf4v3"] +[ext_resource type="Script" path="res://scene/demo01_hello/script/NodeTest.gd" id="2_bus8m"] + +[node name="NodeTest" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +process_thread_group = 2 +process_thread_group_order = 0 +process_thread_messages = 0 +position = Vector2(314, 176) +texture = ExtResource("1_rf4v3") +script = ExtResource("2_bus8m") + +[node name="NodeChild" type="Node2D" parent="Sprite2D"] diff --git a/scene/demo01_hello/script/CustomNode.gd b/scene/demo01_hello/script/CustomNode.gd new file mode 100644 index 0000000..4fa7001 --- /dev/null +++ b/scene/demo01_hello/script/CustomNode.gd @@ -0,0 +1,12 @@ +@icon("res://icon.svg") + +extends Node2D + +class_name MyNode + +@export var a: int = 1 +@export var b: String + +func _ready(): + print("my custom node") + pass diff --git a/scene/demo01_hello/script/HelloWorld.gd b/scene/demo01_hello/script/HelloWorld.gd new file mode 100644 index 0000000..a900b19 --- /dev/null +++ b/scene/demo01_hello/script/HelloWorld.gd @@ -0,0 +1,7 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + print("Hello World") + pass diff --git a/scene/demo01_hello/script/NodeTest.gd b/scene/demo01_hello/script/NodeTest.gd new file mode 100644 index 0000000..77b824a --- /dev/null +++ b/scene/demo01_hello/script/NodeTest.gd @@ -0,0 +1,34 @@ +extends Sprite2D + +var speed: int = 400 + +func _ready(): + print("node test") + pass + + +func _process(delta): + var velocity = Vector2.ZERO # The player's movement vector. + if Input.is_action_pressed("move_right"): + velocity.x += 1 + if Input.is_action_pressed("move_left"): + velocity.x -= 1 + if Input.is_action_pressed("move_down"): + velocity.y += 1 + if Input.is_action_pressed("move_up"): + velocity.y -= 1 + + if velocity.length() <= 0: + return + + velocity = velocity.normalized() * speed + position += velocity * delta + #$NodeChild.position = Vector2.ZERO + #get_parent().position = Vector2.ZERO + #self.call_deferred("myCall") + pass + + +func myCall(): + get_parent().position = Vector2.ZERO + pass diff --git a/scene/demo02_base/base1.tscn b/scene/demo02_base/base1.tscn new file mode 100644 index 0000000..2e71762 --- /dev/null +++ b/scene/demo02_base/base1.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://b7s0egg33pq5j"] + +[ext_resource type="Script" path="res://scene/demo02_base/script/base1.gd" id="1_l5s6b"] + +[node name="Base1" type="Node2D"] +script = ExtResource("1_l5s6b") diff --git a/scene/demo02_base/base2.tscn b/scene/demo02_base/base2.tscn new file mode 100644 index 0000000..03aa4f6 --- /dev/null +++ b/scene/demo02_base/base2.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://2p8k7qtylahq"] + +[ext_resource type="Script" path="res://scene/demo02_base/script/base2.gd" id="1_itqfs"] + +[node name="Base2" type="Node2D"] +script = ExtResource("1_itqfs") diff --git a/scene/demo02_base/base3.tscn b/scene/demo02_base/base3.tscn new file mode 100644 index 0000000..fb0e77b --- /dev/null +++ b/scene/demo02_base/base3.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bkluu2gprqnkl"] + +[ext_resource type="Script" path="res://scene/demo02_base/script/base3.gd" id="1_bxk7m"] + +[node name="Base3" type="Node2D"] +script = ExtResource("1_bxk7m") diff --git a/scene/demo02_base/base4.tscn b/scene/demo02_base/base4.tscn new file mode 100644 index 0000000..0bb002c --- /dev/null +++ b/scene/demo02_base/base4.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://dtb4spakfebfu"] + +[ext_resource type="Script" path="res://scene/demo02_base/script/base4.gd" id="1_usodk"] + +[node name="Base4" type="Node2D"] +script = ExtResource("1_usodk") diff --git a/scene/demo02_base/script/A.gd b/scene/demo02_base/script/A.gd new file mode 100644 index 0000000..b94d17e --- /dev/null +++ b/scene/demo02_base/script/A.gd @@ -0,0 +1,4 @@ +extends RefCounted + +# 表示B对象 +var b diff --git a/scene/demo02_base/script/B.gd b/scene/demo02_base/script/B.gd new file mode 100644 index 0000000..113429b --- /dev/null +++ b/scene/demo02_base/script/B.gd @@ -0,0 +1,4 @@ +extends RefCounted + +# 表示A对象 +var a diff --git a/scene/demo02_base/script/CNode.gd b/scene/demo02_base/script/CNode.gd new file mode 100644 index 0000000..06d59ed --- /dev/null +++ b/scene/demo02_base/script/CNode.gd @@ -0,0 +1,4 @@ +extends Node2D + +func _to_string(): + print("This is C Node2!") diff --git a/scene/demo02_base/script/CReference.gd b/scene/demo02_base/script/CReference.gd new file mode 100644 index 0000000..7815029 --- /dev/null +++ b/scene/demo02_base/script/CReference.gd @@ -0,0 +1,5 @@ +# 如果没有继承任何类,则默认继承RefCounted +extends RefCounted + +func _to_string(): + print("This is C Reference Counted!") diff --git a/scene/demo02_base/script/MyClass.gd b/scene/demo02_base/script/MyClass.gd new file mode 100644 index 0000000..78b44f9 --- /dev/null +++ b/scene/demo02_base/script/MyClass.gd @@ -0,0 +1,185 @@ +@icon("res://icon.svg") + +extends Node2D + +# (optional) class definition with a custom icon +class_name MyClass + +const StringUtils = preload("res://zfoo/util/StringUtils.gd") + +# Member variables +# gds有5种基础类型,Boolean,Integer(Java long),Float(Java double),String,Null + +# &&=and ||=or !=not +var a = (true or false) && true +var b = 9223372036854775807 +var c = 1.5 +var s = "Hello" +var arr = [1, 2, 3] +var dict = { + 2: 3, + "key": "字符串作为key", + arr: "数组作为key" +} +var typed_var: int +var typed_var_float: float +var typed_var_bool: bool +var inferred_type: String = "String" + +# Constants +const ANSWER = 42 +const THE_NAME = "Charly" +# Static filed +static var my_static_field = 42 + +# Enums + +enum {LEFT, RRIGHT, FRONT, BACK} +# 等价于 +# const LEFT = 0 +# const RIGHT = 1 +# const FRONT = 2 +# const BACK = 3 +enum FOOD {GOOD, NORMAL, BAD = -1} + +# Built-in vector types + +var v2 = Vector2(1, 2) +var v3 = Vector3(1, 2, 3) + +func _init(): + print("调用了_init()构造器方法") + pass + +static func getAnswer(): + return ANSWER + +func typeInfo(): + var template = "[Variant:{}] [type:{}] [value:{}]" + print(StringUtils.format(template, [TYPE_BOOL, typeof(a), a])) + print(StringUtils.format(template, [TYPE_INT, typeof(b), b])) + print(StringUtils.format(template, [TYPE_INT, typeof(c), c])) + print(StringUtils.format(template, [TYPE_STRING, typeof(s), s])) + # print(StringUtils.format(template, [TYPE_ARRAY, typeof(arr), arr])) + print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(dict), dict])) + print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(FOOD), FOOD])) + print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(FOOD.GOOD), FOOD.GOOD])) + # 在java中类似于this + print(self is Node) + print(a is Dog) # 类似于instanceof + pass + +func if_function(param1, param2): + if param1 < param2: + print(param1) + elif param2 > 5: + print(param2) + else: + print("Fail!") + pass + + +func switch_function(): + var local_var = 5 + + match local_var: + 1: + print("match1") + 2: + print("match2") + 5: + print("match5") + # continue + 6: + print("match6") + _: + print("match_") + pass + + +func loop_function(): + for i in range(20): + print(i) + var param = 10 + while param != 0: + param -= 1 + return param + +# Function +func arrayIterator(): + # range等价于for(int i = 0; i < 20; i++) + print("数组遍历方法1:") + for i in range(3): + print(i) + print("数组遍历方法2:") + for ele in arr: + print(ele) + print("数组遍历方法3:") + for index in range(arr.size()): + print(arr[index]) + pass + + +func dictionaryIterator(): + print("字典遍历方法1:") + for key in dict: + print("key:" + str(key)) + print("value:" + str(dict[key])) + + print("字典遍历方法2:") + for key in dict.keys(): + print("key:" + str(key)) + print("value:" + str(dict[key])) + + print("字典遍历方法3:") + for value in dict.values(): + print("value:" + str(value)) + pass + + + +func innerClassTest(): + var dog = Dog.new(1) + dog.move() + + dog.info() + dog.height = 2 + dog.info() + pass + +# Inner class,默认继承Object +class Animal: + extends Object # 如果不指定继承的类,默认基础Object + const STATIC_FIELD = "静态变量" + # 属性 + var height: int + + func _init(): + print("Animal 构造方法") + + func move(): + print("animal,移动") + + static func staticFuction(): + pass + +class Dog: + extends Animal + + # Constructor + func _init(_height): + self.height = _height + print("Dog 构造方法") + pass + + # Functions override functions with the same name on the base/parent class. + func move(): + print("dog,用4个脚跑") + # If you still want to call them, use '.' (like 'super' in other languages). + super.move() + pass + + func info(_parm = 100): + print("height:" + str(height)) + pass + diff --git a/scene/demo02_base/script/base1.gd b/scene/demo02_base/script/base1.gd new file mode 100644 index 0000000..57b451a --- /dev/null +++ b/scene/demo02_base/script/base1.gd @@ -0,0 +1,55 @@ +extends Node2D + + +# 导出一个数字 +@export var a = 1 +# 导出一个节点路径 +@export var b:NodePath +# 导出一个文件路径 +@export_file var sound_effect_path: String +# 导出一个文件路径,以txt结尾 +@export_file("*.txt") var notes_path: String + + +func _init(): + print("init") + + +# Called when the node enters the scene tree for the first time. +func _ready(): + print("ready") + print("new一个对象--------------------------------") + var myClass = MyClass.new() + print(myClass.to_string()) + + print("数据类型信息--------------------------------") + myClass.typeInfo() + + print("基础语法if else--------------------------------") + myClass.if_function(1, 2) + + print("基础语法switch--------------------------------") + myClass.switch_function() + + print("基础语法while for--------------------------------") + myClass.loop_function() + + print("数组遍历--------------------------------") + myClass.arrayIterator() + + print("字典遍历--------------------------------") + myClass.dictionaryIterator() + + print("访问常量--------------------------------") + var answer = MyClass.ANSWER + print("访问const变量,类似于static变量:" + str(answer)) + print("访问静态变量--------------------------------") + print("访问static变量,类似于static变量:" + str(MyClass.my_static_field)) + print("调用静态方法--------------------------------") + print("调用静态方法:" + str(MyClass.getAnswer())) + + print("内部类测试--------------------------------") + myClass.innerClassTest() + pass + + diff --git a/scene/demo02_base/script/base2.gd b/scene/demo02_base/script/base2.gd new file mode 100644 index 0000000..5cfc8e5 --- /dev/null +++ b/scene/demo02_base/script/base2.gd @@ -0,0 +1,48 @@ +extends Node2D + +const CNode = preload("res://scene/demo02_base/script/CNode.gd") +const CReference = preload("res://scene/demo02_base/script/CReference.gd") + +# monitor初探 +func _ready(): + #nodeTest() + #nodeFreeTest() + #nodeQueueFreeTest() + #referenceTest() + #referenceFreeTest() + referencUnreferenceTest() + pass + + +func nodeTest(): + for i in range(10000): + var _instance = CNode.new() + + +func nodeFreeTest(): + for i in range(10000): + var instance = CNode.new() + instance.free() + +# queue_free效率更高 +func nodeQueueFreeTest(): + for i in range(10000): + var instance = CNode.new() + instance.queue_free() + +func referenceTest(): + for i in range(10000): + var _instance = CReference.new() + + +func referenceFreeTest(): + for i in range(10000): + var instance = CReference.new() + instance.free() + +# 4.x主动调用unreference会导致没有被回收对象 +func referencUnreferenceTest(): + for i in range(10000): + var instance = CReference.new() + instance.reference() + instance.unreference() diff --git a/scene/demo02_base/script/base3.gd b/scene/demo02_base/script/base3.gd new file mode 100644 index 0000000..469ded3 --- /dev/null +++ b/scene/demo02_base/script/base3.gd @@ -0,0 +1,38 @@ +extends Node2D + +const A = preload("res://scene/demo02_base/script/A.gd") +const B = preload("res://scene/demo02_base/script/B.gd") + +func _ready(): + #referenceTest() + #referenceCycleTest() + #referenceUnreference1Test() + #referenceUnreference2Test() + pass + + +func referenceTest(): + var a = A.new() + var b = B.new() + +func referenceCycleTest(): + var a = A.new() + var b = B.new() + a.b = b + b.a = a + + +func referenceUnreference1Test(): + var a = A.new() + var b = B.new() + a.b = b + b.a = a + a.unreference() + +func referenceUnreference2Test(): + var a = A.new() + var b = B.new() + a.b = b + b.a = a + a.unreference() + b.unreference() diff --git a/scene/demo02_base/script/base4.gd b/scene/demo02_base/script/base4.gd new file mode 100644 index 0000000..27d4aa7 --- /dev/null +++ b/scene/demo02_base/script/base4.gd @@ -0,0 +1,27 @@ +extends Node2D + + +func _ready(): + # new一个Sprite节点 + var sprite = Sprite2D.new() + # 设置图片 + var icon = preload("res://icon.svg") + sprite.set_texture(icon) + + # 修改名称 + sprite.name = "mynode" + + # 修改坐标居中 + sprite.position.x = 200 + sprite.position.y = 200 + + # 添加到当前的场景中 + add_child(sprite) + pass + + + +func _process(delta): + var sprite: Sprite2D = $mynode + sprite.rotate(0.1) + pass diff --git a/scene/demo03_lifecycle/life_cycle.tscn b/scene/demo03_lifecycle/life_cycle.tscn new file mode 100644 index 0000000..b26be98 --- /dev/null +++ b/scene/demo03_lifecycle/life_cycle.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://bnqtr1vlp0npl"] + +[ext_resource type="Script" path="res://scene/demo03_lifecycle/script/parent.gd" id="1_pcyfp"] +[ext_resource type="Script" path="res://scene/demo03_lifecycle/script/sub_node1.gd" id="2_51utr"] +[ext_resource type="Script" path="res://scene/demo03_lifecycle/script/sub_node2.gd" id="3_8nf4e"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_pcyfp") + +[node name="SubNode1" type="Node2D" parent="."] +script = ExtResource("2_51utr") + +[node name="SubNode2" type="Node" parent="SubNode1"] +script = ExtResource("3_8nf4e") + +[node name="DeleteButton" type="Button" parent="."] +offset_left = 595.0 +offset_top = 258.0 +offset_right = 742.0 +offset_bottom = 307.0 +text = "Delete SubNode1" diff --git a/scene/demo03_lifecycle/script/parent.gd b/scene/demo03_lifecycle/script/parent.gd new file mode 100644 index 0000000..9fa8b1f --- /dev/null +++ b/scene/demo03_lifecycle/script/parent.gd @@ -0,0 +1,41 @@ +extends Node2D + +const NodeUtils = preload("res://zfoo/util/NodeUtils.gd") + +func _enter_tree(): + # When the node enters the Scene Tree, it becomes active + # and this function is called. Children nodes have not entered + # the active scene yet. In general, it's better to use _ready() + # for most cases. + print("parent _enter_tree") + +func _ready(): + # This function is called after _enter_tree, but it ensures + # that all children nodes have also entered the Scene Tree, + # and became active. + print("parent _ready") + $DeleteButton.connect("pressed", Callable(self, "deleteSubNode1")) + +func _exit_tree(): + # When the node exits the Scene Tree, this function is called. + # Children nodes have all exited the Scene Tree at this point + # and all became inactive. + print("parent _exit_tree") + + +func deleteSubNode1(): + var root = get_tree().root + root.remove_child(self) + + #注意monitor监视窗口的object变化,和node变化,由于组合一个节点可能包含多个对象 + #self.queue_free() + + #remove_child只能移除子节点,无法移除子节点的子节点 + #get_tree().root.remove_child(self) + #remove_child($SubNode1) + + #先增加再删除 + #root.add_child(self) + + #为了简单,可以使用统一的封装方法,门面模式 + #NodeUtils.removeNode(self) diff --git a/scene/demo03_lifecycle/script/sub_node1.gd b/scene/demo03_lifecycle/script/sub_node1.gd new file mode 100644 index 0000000..ffd6cb7 --- /dev/null +++ b/scene/demo03_lifecycle/script/sub_node1.gd @@ -0,0 +1,48 @@ +extends Node2D + + +func _enter_tree(): + # When the node enters the Scene Tree, it becomes active + # and this function is called. Children nodes have not entered + # the active scene yet. In general, it's better to use _ready() + # for most cases. + print("sub node1 _enter_tree") + +func _ready(): + # This function is called after _enter_tree, but it ensures + # that all children nodes have also entered the Scene Tree, + # and became active. + print("sub node1 _ready") + #nodeUsage() + +func _exit_tree(): + # When the node exits the Scene Tree, this function is called. + # Children nodes have all exited the Scene Tree at this point + # and all became inactive. + print("sub node1 _exit_tree") + + +# 申明和存储节点,等价于在_ready()下赋值 +@onready var readySubNode = $SubNode2 + +func nodeUsage(): + # 获取当前节点 + var currentNode1 = $"." + var currentNode2 = self + # 获取父节点 + var parentNode1 = get_parent() + var parentNode2 = $"../" + # 获取子节点 + var subNode1 = $SubNode2 + var subNode2 = $"SubNode2" + var subNode3 = get_node("SubNode2") + # 根节点查找法,会返回节点树从上到下找到的第一个节点 + var subNode4 = get_tree().root.find_node("SubNode2", true, false) + print(currentNode1.name) + print(currentNode2.name) + print(parentNode1.name) + print(parentNode2.name) + print(subNode1.name) + print(subNode2.name) + print(subNode3.name) + print(subNode4.name) diff --git a/scene/demo03_lifecycle/script/sub_node2.gd b/scene/demo03_lifecycle/script/sub_node2.gd new file mode 100644 index 0000000..3ce5f1d --- /dev/null +++ b/scene/demo03_lifecycle/script/sub_node2.gd @@ -0,0 +1,23 @@ +extends Node + + +func _enter_tree(): + # When the node enters the Scene Tree, it becomes active + # and this function is called. Children nodes have not entered + # the active scene yet. In general, it's better to use _ready() + # for most cases. + print("sub node2 _enter_tree") + +func _ready(): + # This function is called after _enter_tree, but it ensures + # that all children nodes have also entered the Scene Tree, + # and became active. + print("sub node2 _ready") + +func _exit_tree(): + # When the node exits the Scene Tree, this function is called. + # Children nodes have all exited the Scene Tree at this point + # and all became inactive. + print("sub node2 _exit_tree") + + diff --git a/scene/demo04_signal/script/await.gd b/scene/demo04_signal/script/await.gd new file mode 100644 index 0000000..6a0dd5f --- /dev/null +++ b/scene/demo04_signal/script/await.gd @@ -0,0 +1,25 @@ +extends Button + + +func _ready(): + self.connect("pressed", Callable(self, "onButton")) + +func onButton(): + var yieldResult1 = await doSomething1() + + var yieldResult2 = await doSomething2() + # 等待yieldResult2执行完毕 + print("end") + + +func doSomething1(): + await print("doSomething") + +func doSomething2(): + print(1) + await get_tree().create_timer(1).timeout + print(2) + await get_tree().create_timer(1).timeout + print(3) + await get_tree().create_timer(1).timeout + pass diff --git a/scene/demo04_signal/script/mySignal.gd b/scene/demo04_signal/script/mySignal.gd new file mode 100644 index 0000000..163b9ac --- /dev/null +++ b/scene/demo04_signal/script/mySignal.gd @@ -0,0 +1,22 @@ +extends Button + + +# 自定义信号 +signal mySignal(a, b) + +# 发送信号 +# emit_signal("mySignal", 1, 2) +# disconnect("mySignal", 1, 2) + +# 类似于设计模式中的观察者 +func _ready(): + self.connect("mySignal", Callable(self, "onMySingalCallback")) + self.connect("pressed", Callable(self, "onButton")) + + +func onMySingalCallback(a, b): + print("a:" + str(a)) + print("b:" + str(b)) + +func onButton(): + emit_signal("mySignal", 1, 2) diff --git a/scene/demo04_signal/script/signal.gd b/scene/demo04_signal/script/signal.gd new file mode 100644 index 0000000..461a0bf --- /dev/null +++ b/scene/demo04_signal/script/signal.gd @@ -0,0 +1,16 @@ +extends Node2D + + +# 第一种信号接受方法,通过在场景中配置信号的接收方法 +func _on_button_1_pressed(): + print("hello button1") + + + +# 第二种信号接受方法,通过代码控制信号的接受,更加的灵活,比较推荐方式 +func _ready(): + $Button2.connect("pressed", Callable(self, "onButton2")) + +func onButton2(): + print("button2 pressed") + diff --git a/scene/demo04_signal/signal.tscn b/scene/demo04_signal/signal.tscn new file mode 100644 index 0000000..a6244b2 --- /dev/null +++ b/scene/demo04_signal/signal.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=5 format=3 uid="uid://dbxj3ocgvec8"] + +[ext_resource type="Script" path="res://scene/demo04_signal/script/signal.gd" id="1_dadg8"] +[ext_resource type="Script" path="res://scene/demo04_signal/script/mySignal.gd" id="2_lvqsi"] +[ext_resource type="Script" path="res://scene/demo04_signal/script/await.gd" id="3_4hptw"] +[ext_resource type="Script" path="res://scene/demo04_signal/thread.gd" id="4_r6xio"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_dadg8") + +[node name="Button1" type="Button" parent="."] +offset_left = 126.0 +offset_top = 62.0 +offset_right = 240.0 +offset_bottom = 109.0 +text = "button1" + +[node name="Button2" type="Button" parent="."] +offset_left = 394.0 +offset_top = 62.0 +offset_right = 485.0 +offset_bottom = 111.0 +text = "button2" + +[node name="MySignal" type="Button" parent="."] +offset_left = 141.0 +offset_top = 222.0 +offset_right = 245.0 +offset_bottom = 271.0 +text = "mySignal" +script = ExtResource("2_lvqsi") + +[node name="Await" type="Button" parent="."] +offset_left = 132.0 +offset_top = 354.0 +offset_right = 225.0 +offset_bottom = 398.0 +text = "await" +script = ExtResource("3_4hptw") + +[node name="Thread" type="Button" parent="."] +offset_left = 141.0 +offset_top = 497.0 +offset_right = 235.0 +offset_bottom = 545.0 +text = "thread" +script = ExtResource("4_r6xio") + +[connection signal="pressed" from="Button1" to="." method="_on_button_1_pressed"] diff --git a/scene/demo04_signal/thread.gd b/scene/demo04_signal/thread.gd new file mode 100644 index 0000000..3e307c8 --- /dev/null +++ b/scene/demo04_signal/thread.gd @@ -0,0 +1,29 @@ +extends Button + +func _ready(): + self.connect("pressed", Callable(self, "onButton2")) + +func onButton2(): + var myThread = Thread.new() + + print("Create Thread Id: ", myThread) + print("Thread Active: ", myThread.is_alive()) + + myThread.start(Callable(self, "threadTest")) + + print() + print("Thread Active: ", myThread.is_alive()) + + var waitForThread = myThread.wait_to_finish() # wait for our thread to finish before moving on + + print() + print("Thread is Finished with result: ", waitForThread) + print("Thread Active: ", myThread.is_alive()) + + + + +# 使用thread运行的函数必须有一个参数,要不然无法运行 +func threadTest(): + print("thread test start") + return 999 diff --git a/scene/demo05_scene_node/scene_node.tscn b/scene/demo05_scene_node/scene_node.tscn new file mode 100644 index 0000000..a51b6a1 --- /dev/null +++ b/scene/demo05_scene_node/scene_node.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://12um7dx1w0gp"] + +[ext_resource type="Script" path="res://scene/demo05_scene_node/script/hero.gd" id="1_cqv88"] +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="1_xf37n"] + +[node name="Node2D" type="Node2D"] +position = Vector2(100, 100) + +[node name="Hero" type="Sprite2D" parent="."] +position = Vector2(400, 200) +texture = ExtResource("1_xf37n") +script = ExtResource("1_cqv88") diff --git a/scene/demo05_scene_node/script/hero.gd b/scene/demo05_scene_node/script/hero.gd new file mode 100644 index 0000000..fcee78c --- /dev/null +++ b/scene/demo05_scene_node/script/hero.gd @@ -0,0 +1,87 @@ +extends Sprite2D + +const StringUtils = preload("res://zfoo/util/StringUtils.gd") + + +var gameWidth: int +var gameHeight: int +var spriteWidth: int +var spriteHeight: int + + + +func _enter_tree(): + windowPositionTest() + #positionTest() + #textureTest() + pass + + +func _physics_process(delta): + setupGameWindow() + setupSprite() + positionTopCenter() + pass + +# 屏幕坐标系 +func windowPositionTest(): + # 设置游戏屏幕的位置 + # DisplayServer.window_set_size(Vector2(100, 100)) + # DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + print(StringUtils.format("屏幕大小[{}]", [DisplayServer.window_get_size()])) + print(StringUtils.format("屏幕位置[{}]", [DisplayServer.window_get_position()])) + pass + +# 坐标点测试用例 +func positionTest(): + print(position) + print(global_position) + print(to_global(position)) + print(to_local(global_position)) + pass + + +func setupGameWindow(): + gameWidth = DisplayServer.window_get_size().x + gameHeight = DisplayServer.window_get_size().y + +func setupSprite(): + spriteWidth = texture.get_width() + spriteHeight = texture.get_height() + + +func positionTopCenter() -> void: + #get_parent().position.x = 0 + #get_parent().position.y = 0 + #self.global_position + self.position.x = gameWidth / 2 + self.position.y = spriteHeight / 2 + +func positionCenter() -> void: + self.global_position.x = gameWidth / 2 + self.global_position.y = gameHeight / 2 + +func positionBottomCenter() -> void: + self.global_position.x = gameWidth / 2 + self.global_position.y = gameHeight - spriteHeight / 2 + +func positionLeftCenter() -> void: + self.global_position.x = spriteWidth / 2 + self.global_position.y = gameHeight / 2 + + + +# 纹理测试用例 +func textureTest(): + var texture = get_texture() + var image = texture.get_image() + print(offset) + print("texture type: ", texture) + print("height: ", texture.get_height()) + print("width: ", texture.get_width()) + + # 无法直接编辑图片 + image.shrink_x2() + #这样做会破坏项目的资源,使资源变得混乱 + image.save_png("D:\\newImage.png") + pass diff --git a/scene/demo06_move/move.tscn b/scene/demo06_move/move.tscn new file mode 100644 index 0000000..30ff4ee --- /dev/null +++ b/scene/demo06_move/move.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="uid://c8r1o5j3f8r80"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="1_qmgyw"] +[ext_resource type="Script" path="res://scene/demo06_move/script/move.gd" id="2_uwquj"] + +[node name="Node2D" type="Node2D"] + +[node name="HeroMove" type="Sprite2D" parent="."] +position = Vector2(375, 221) +texture = ExtResource("1_qmgyw") +script = ExtResource("2_uwquj") diff --git a/scene/demo06_move/script/move.gd b/scene/demo06_move/script/move.gd new file mode 100644 index 0000000..560f45f --- /dev/null +++ b/scene/demo06_move/script/move.gd @@ -0,0 +1,31 @@ +extends Sprite2D + + +# How fast the player will move (pixels/sec). +@export var speed = 400 +# Size of the game window. +var screen_size + + +func _ready(): + screen_size = get_viewport_rect().size + + +func _process(delta): + var velocity = Vector2.ZERO # The player's movement vector. + if Input.is_action_pressed("move_right"): + velocity.x += 1 + if Input.is_action_pressed("move_left"): + velocity.x -= 1 + if Input.is_action_pressed("move_down"): + velocity.y += 1 + if Input.is_action_pressed("move_up"): + velocity.y -= 1 + + if velocity.length() <= 0: + return + + velocity = velocity.normalized() * speed + position += velocity * delta + position.x = clamp(position.x, 0, screen_size.x) + position.y = clamp(position.y, 0, screen_size.y) diff --git a/scene/demo07_collision/collision.tscn b/scene/demo07_collision/collision.tscn new file mode 100644 index 0000000..bb891a0 --- /dev/null +++ b/scene/demo07_collision/collision.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=5 format=3 uid="uid://c31rpyh5mxyn2"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="1_dr3sv"] +[ext_resource type="Script" path="res://scene/demo07_collision/script/characterBody2D.gd" id="2_dhi5g"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_o1364"] +size = Vector2(128, 128) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_a33y2"] +size = Vector2(130, 126) + +[node name="Node2D" type="Node2D"] + +[node name="RigidBody2D" type="RigidBody2D" parent="."] +position = Vector2(775, 89) +metadata/_edit_group_ = true + +[node name="Sprite" type="Sprite2D" parent="RigidBody2D"] +texture = ExtResource("1_dr3sv") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] +shape = SubResource("RectangleShape2D_o1364") + +[node name="CharacterBody2D" type="CharacterBody2D" parent="."] +position = Vector2(417, 201) +script = ExtResource("2_dhi5g") +metadata/_edit_group_ = true + +[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"] +texture = ExtResource("1_dr3sv") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] +shape = SubResource("RectangleShape2D_a33y2") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] +polygon = PackedVector2Array(61, 268, 60, 607, 1043, 615, 1051, 216, 995, 220, 691, 547, 133, 542, 137, 270) + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"] +color = Color(0.972549, 0.843137, 0.85098, 1) +polygon = PackedVector2Array(62, 269, 58, 606, 1041, 614, 1050, 214, 992, 220, 688, 549, 132, 541, 134, 269) diff --git a/scene/demo07_collision/script/characterBody2D.gd b/scene/demo07_collision/script/characterBody2D.gd new file mode 100644 index 0000000..a8aad0a --- /dev/null +++ b/scene/demo07_collision/script/characterBody2D.gd @@ -0,0 +1,30 @@ +extends CharacterBody2D + + +# How fast the player will move (pixels/sec). +@export var speed = 400 +# Size of the game window. +var screen_size + +func _ready(): + screen_size = get_viewport_rect().size + +func _physics_process(delta): + var velocity = Vector2.ZERO # The player's movement vector. + if Input.is_action_pressed("move_right"): + velocity.x += 1 + if Input.is_action_pressed("move_left"): + velocity.x -= 1 + if Input.is_action_pressed("move_down"): + velocity.y += 1 + if Input.is_action_pressed("move_up"): + velocity.y -= 1 + + if velocity.length() <= 0: + return + + velocity = velocity.normalized() * speed + # false这个选项参数看意思是把无限惯性关了,这个关了之后就不会向碰撞的刚体施加作用力,需要你自己去写 + var info: KinematicCollision2D = move_and_collide(velocity * delta) + if info != null: + print(info.get_collider()) 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/Grasslands.png.import b/scene/demo08_path/image/Grasslands.png.import new file mode 100644 index 0000000..e8eb7c5 --- /dev/null +++ b/scene/demo08_path/image/Grasslands.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b2kiyycgqh3yv" +path="res://.godot/imported/Grasslands.png-0a6ab77180659e2e9d9a66e9712b5531.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo08_path/image/Grasslands.png" +dest_files=["res://.godot/imported/Grasslands.png-0a6ab77180659e2e9d9a66e9712b5531.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 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/Robi.png.import b/scene/demo08_path/image/Robi.png.import new file mode 100644 index 0000000..bc2af76 --- /dev/null +++ b/scene/demo08_path/image/Robi.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cdn4iyiywnm2f" +path="res://.godot/imported/Robi.png-6434141f148b69577a114e3ae4050d96.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo08_path/image/Robi.png" +dest_files=["res://.godot/imported/Robi.png-6434141f148b69577a114e3ae4050d96.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo08_path/line.tscn b/scene/demo08_path/line.tscn new file mode 100644 index 0000000..2788fbb --- /dev/null +++ b/scene/demo08_path/line.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=5 format=3 uid="uid://dbh46yr5q0cve"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="2_316ts"] +[ext_resource type="Script" path="res://scene/demo08_path/script/pathFollow2D.gd" id="3_pk2oc"] +[ext_resource type="Script" path="res://scene/demo08_path/script/player.gd" id="3_t2423"] + +[sub_resource type="Curve2D" id="Curve2D_tde6t"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, 54, 290, 0, 0, 0, 0, 185, 163, 0, 0, 0, 0, 365, 341, 0, 0, 0, 0, 486, 147, 0, 0, 0, 0, 554, 404, 0, 0, 0, 0, 598, 561, 0, 0, 0, 0, 711, 599, 0, 0, 0, 0, 785, 259, 0, 0, 0, 0, 961, 55, 0, 0, 0, 0, 1016, 257, 0, 0, 0, 0, 961, 370, 0, 0, 0, 0, 1014, 563) +} +point_count = 12 + +[node name="Node2D" type="Node2D"] + +[node name="Player" type="Sprite2D" parent="."] +position = Vector2(54, 290) +rotation = -0.769896 +texture = ExtResource("2_316ts") +script = ExtResource("3_t2423") + +[node name="Path2D" type="Path2D" parent="."] +curve = SubResource("Curve2D_tde6t") + +[node name="PathFollow2D" type="PathFollow2D" parent="Path2D"] +position = Vector2(54, 290) +rotation = -0.769896 +script = ExtResource("3_pk2oc") + +[node name="RemoteTransform2D" type="RemoteTransform2D" parent="Path2D/PathFollow2D"] +remote_path = NodePath("../../../Player") diff --git a/scene/demo08_path/path.tscn b/scene/demo08_path/path.tscn new file mode 100644 index 0000000..44fb5bc --- /dev/null +++ b/scene/demo08_path/path.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://3ewt17t0c0sv"] + +[ext_resource type="Script" path="res://scene/demo08_path/script/line2D.gd" id="1_mascd"] +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="2_28vki"] +[ext_resource type="Script" path="res://scene/demo08_path/script/player.gd" id="3_xgm4i"] + +[sub_resource type="Curve" id="Curve_y6lw1"] +_data = [Vector2(0.00985222, 0.0242664), 0.0, 0.0, 0, 0, Vector2(0.342365, 0.500296), 0.0, 0.0, 0, 0, Vector2(0.635468, 0.669426), 0.0, 0.0, 0, 0, Vector2(0.775862, 0.857776), 0.0, 0.0, 0, 0, Vector2(0.997537, 1), 0.0, 0.0, 0, 0] +point_count = 5 + +[node name="Node2D" type="Node2D"] + +[node name="Line2D" type="Line2D" parent="."] +width = 100.0 +width_curve = SubResource("Curve_y6lw1") +default_color = Color(1, 1, 0.0627451, 1) +script = ExtResource("1_mascd") + +[node name="Player" type="Sprite2D" parent="."] +position = Vector2(205, 110) +texture = ExtResource("2_28vki") +script = ExtResource("3_xgm4i") diff --git a/scene/demo08_path/script/line2D.gd b/scene/demo08_path/script/line2D.gd new file mode 100644 index 0000000..64f08bb --- /dev/null +++ b/scene/demo08_path/script/line2D.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_child("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 diff --git a/scene/demo08_path/script/pathFollow2D.gd b/scene/demo08_path/script/pathFollow2D.gd new file mode 100644 index 0000000..51deff9 --- /dev/null +++ b/scene/demo08_path/script/pathFollow2D.gd @@ -0,0 +1,5 @@ +extends PathFollow2D + + +func _process(delta): + progress += 8 diff --git a/scene/demo08_path/script/player.gd b/scene/demo08_path/script/player.gd new file mode 100644 index 0000000..560f45f --- /dev/null +++ b/scene/demo08_path/script/player.gd @@ -0,0 +1,31 @@ +extends Sprite2D + + +# How fast the player will move (pixels/sec). +@export var speed = 400 +# Size of the game window. +var screen_size + + +func _ready(): + screen_size = get_viewport_rect().size + + +func _process(delta): + var velocity = Vector2.ZERO # The player's movement vector. + if Input.is_action_pressed("move_right"): + velocity.x += 1 + if Input.is_action_pressed("move_left"): + velocity.x -= 1 + if Input.is_action_pressed("move_down"): + velocity.y += 1 + if Input.is_action_pressed("move_up"): + velocity.y -= 1 + + if velocity.length() <= 0: + return + + velocity = velocity.normalized() * speed + position += velocity * delta + position.x = clamp(position.x, 0, screen_size.x) + position.y = clamp(position.y, 0, screen_size.y) diff --git a/scene/demo08_path/script/tile.gd b/scene/demo08_path/script/tile.gd new file mode 100644 index 0000000..d8419d3 --- /dev/null +++ b/scene/demo08_path/script/tile.gd @@ -0,0 +1,31 @@ +extends Node2D + + +@onready var nav_2d : NavigationAgent2D = $Player/NavigationAgent2D +@onready var player : CharacterBody2D = $Player +@onready var line2D : Line2D = $Line2D + +var speed = 250 + +func _physics_process(delta): + if nav_2d.is_navigation_finished() || nav_2d.get_final_position() == Vector2.ZERO: + return + + var next_location = nav_2d.get_next_path_position() + var direction = player.global_position.direction_to(next_location) + + nav_2d.set_velocity(direction * speed) + player.velocity = direction * speed + player.move_and_slide() + +func _unhandled_input(event: InputEvent) -> void: + if not event is InputEventMouseButton: + return + + var playerPosition = player.get_global_position() + var mousePosition = event.get_global_position() + nav_2d.set_target_position(mousePosition) + nav_2d.get_next_path_position() + var navPath = nav_2d.get_current_navigation_path() + line2D.points = navPath + diff --git a/scene/demo08_path/tile.tscn b/scene/demo08_path/tile.tscn new file mode 100644 index 0000000..6e25619 --- /dev/null +++ b/scene/demo08_path/tile.tscn @@ -0,0 +1,149 @@ +[gd_scene load_steps=9 format=3 uid="uid://b0dm0cogxc3y6"] + +[ext_resource type="Script" path="res://scene/demo08_path/script/tile.gd" id="1_6iolp"] +[ext_resource type="Texture2D" uid="uid://b2kiyycgqh3yv" path="res://scene/demo08_path/image/Grasslands.png" id="2_4p2ab"] +[ext_resource type="Texture2D" uid="uid://cdn4iyiywnm2f" path="res://scene/demo08_path/image/Robi.png" id="3_3q3se"] + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_5gwiy"] +vertices = PackedVector2Array(40, 40, -40, 40, -40, -40, 40, -40) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40)]) +source_geometry_group_name = &"navigation_polygon_source_group" +agent_radius = 0.0 + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_3ksr3"] +vertices = PackedVector2Array(40, 40, -40, 40, -40, -40, 40, -40) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40)]) +source_geometry_group_name = &"navigation_polygon_source_group" +agent_radius = 0.0 + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0pcpq"] +texture = ExtResource("2_4p2ab") +texture_region_size = Vector2i(80, 80) +0:0/0 = 0 +0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:0/0/physics_layer_0/angular_velocity = 0.0 +0:0/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +1:0/0 = 0 +1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:0/0/physics_layer_0/angular_velocity = 0.0 +1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40) +2:0/0 = 0 +2:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:0/0/physics_layer_0/angular_velocity = 0.0 +2:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40) +3:0/0 = 0 +3:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:0/0/physics_layer_0/angular_velocity = 0.0 +3:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40) +4:0/0 = 0 +4:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +4:0/0/physics_layer_0/angular_velocity = 0.0 +4:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-40, -40, 40, -40, 40, 40, -40, 40) +0:1/0 = 0 +0:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:1/0/physics_layer_0/angular_velocity = 0.0 +0:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +1:1/0 = 0 +1:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:1/0/physics_layer_0/angular_velocity = 0.0 +1:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +2:1/0 = 0 +2:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:1/0/physics_layer_0/angular_velocity = 0.0 +2:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +3:1/0 = 0 +3:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:1/0/physics_layer_0/angular_velocity = 0.0 +3:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +4:1/0 = 0 +4:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +4:1/0/physics_layer_0/angular_velocity = 0.0 +4:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +5:1/0 = 0 +5:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +5:1/0/physics_layer_0/angular_velocity = 0.0 +5:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +6:1/0 = 0 +6:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +6:1/0/physics_layer_0/angular_velocity = 0.0 +6:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_5gwiy") +0:2/0 = 0 +0:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:2/0/physics_layer_0/angular_velocity = 0.0 +0:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +1:2/0 = 0 +1:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:2/0/physics_layer_0/angular_velocity = 0.0 +1:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +2:2/0 = 0 +2:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:2/0/physics_layer_0/angular_velocity = 0.0 +2:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +3:2/0 = 0 +3:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:2/0/physics_layer_0/angular_velocity = 0.0 +3:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +4:2/0 = 0 +4:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +4:2/0/physics_layer_0/angular_velocity = 0.0 +4:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +5:2/0 = 0 +5:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +5:2/0/physics_layer_0/angular_velocity = 0.0 +5:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +0:3/0 = 0 +0:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:3/0/physics_layer_0/angular_velocity = 0.0 +0:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +1:3/0 = 0 +1:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:3/0/physics_layer_0/angular_velocity = 0.0 +1:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +2:3/0 = 0 +2:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:3/0/physics_layer_0/angular_velocity = 0.0 +2:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +3:3/0 = 0 +3:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:3/0/physics_layer_0/angular_velocity = 0.0 +3:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +4:3/0 = 0 +4:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +4:3/0/physics_layer_0/angular_velocity = 0.0 +4:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") +5:3/0 = 0 +5:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +5:3/0/physics_layer_0/angular_velocity = 0.0 +5:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ksr3") + +[sub_resource type="TileSet" id="TileSet_0evj0"] +tile_size = Vector2i(80, 80) +physics_layer_0/collision_layer = 1 +navigation_layer_0/layers = 1 +sources/0 = SubResource("TileSetAtlasSource_0pcpq") + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_82yhd"] +size = Vector2(18, 16) + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_6iolp") + +[node name="TileMap" type="TileMap" parent="."] +tile_set = SubResource("TileSet_0evj0") +format = 2 +layer_0/tile_data = PackedInt32Array(0, 0, 0, 1, 0, 0, 2, 0, 0, 65537, 0, 0, 65538, 0, 0, 131074, 0, 0, 131075, 65536, 0, 3, 65536, 0, 4, 0, 0, 65540, 0, 0, 5, 0, 0, 65541, 0, 0, 131077, 0, 0, 131078, 0, 0, 6, 0, 0, 65542, 0, 0, 131079, 0, 0, 196609, 0, 0, 196610, 0, 0, 196611, 65536, 0, 196612, 0, 0, 196613, 0, 0, 262149, 0, 0, 262150, 131072, 0, 327686, 131072, 0, 327681, 0, 0, 327682, 0, 0, 393218, 0, 0, 393219, 0, 0, 458755, 0, 0, 458756, 0, 0, 327684, 0, 0, 327685, 0, 0, 393222, 131072, 0, 393223, 0, 0, 458760, 0, 0, 196615, 0, 0, 262152, 0, 0, 327689, 196608, 0, 393226, 0, 0, 458763, 262144, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0, 262144, 0, 0, 327680, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 131073, 0, 0, 262145, 0, 0, 393217, 0, 0, 458753, 0, 0, 524289, 0, 0, 262146, 0, 0, 458754, 0, 0, 524290, 0, 0, 65539, 65536, 0, 262147, 65536, 0, 327683, 65536, 0, 524291, 0, 0, 131076, 0, 0, 262148, 0, 0, 393220, 0, 0, 524292, 0, 0, 393221, 0, 0, 458757, 0, 0, 524293, 0, 0, 196614, 131072, 0, 458758, 131072, 0, 524294, 131072, 0, 7, 0, 0, 65543, 0, 0, 262151, 0, 0, 327687, 0, 0, 458759, 0, 0, 524295, 0, 0, 8, 0, 0, 65544, 0, 0, 131080, 0, 0, 196616, 0, 0, 327688, 0, 0, 393224, 0, 0, 524296, 0, 0, 9, 196608, 0, 65545, 196608, 0, 131081, 196608, 0, 196617, 196608, 0, 262153, 196608, 0, 393225, 0, 0, 458761, 0, 0, 524297, 0, 0, 10, 0, 0, 65546, 0, 0, 131082, 0, 0, 196618, 0, 0, 262154, 0, 0, 327690, 0, 0, 458762, 0, 0, 524298, 0, 0, 11, 0, 0, 65547, 0, 0, 131083, 0, 0, 196619, 262144, 0, 262155, 65536, 2, 327691, 65536, 2, 393227, 65536, 2, 524299, 0, 0, 12, 0, 0, 65548, 0, 0, 131084, 0, 0, 196620, 262144, 0, 262156, 65536, 2, 327692, 65536, 2, 393228, 65536, 2, 458764, 262144, 0, 524300, 0, 0, 13, 0, 0, 65549, 0, 0, 131085, 0, 0, 196621, 262144, 0, 262157, 65536, 2, 327693, 65536, 2, 393229, 65536, 2, 458765, 262144, 0, 524301, 0, 0, 14, 0, 0, 65550, 0, 0, 131086, 0, 0, 196622, 262144, 0, 262158, 65536, 2, 327694, 65536, 2, 393230, 65536, 2, 458766, 262144, 0, 524302, 0, 0) + +[node name="Line2D" type="Line2D" parent="."] + +[node name="Player" type="CharacterBody2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Player"] +scale = Vector2(0.205279, 0.205279) +texture = ExtResource("3_3q3se") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource("RectangleShape2D_82yhd") + +[node name="NavigationAgent2D" type="NavigationAgent2D" parent="Player"] diff --git a/scene/demo09_canvas/BarlowCondensed-Bold.ttf b/scene/demo09_canvas/BarlowCondensed-Bold.ttf new file mode 100644 index 0000000..8fbdd9b Binary files /dev/null and b/scene/demo09_canvas/BarlowCondensed-Bold.ttf differ diff --git a/scene/demo09_canvas/BarlowCondensed-Bold.ttf.import b/scene/demo09_canvas/BarlowCondensed-Bold.ttf.import new file mode 100644 index 0000000..3605b92 --- /dev/null +++ b/scene/demo09_canvas/BarlowCondensed-Bold.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://dy4h5b6wj8n5o" +path="res://.godot/imported/BarlowCondensed-Bold.ttf-c54c973ad70fe2834c825f6140d0601a.fontdata" + +[deps] + +source_file="res://scene/demo09_canvas/BarlowCondensed-Bold.ttf" +dest_files=["res://.godot/imported/BarlowCondensed-Bold.ttf-c54c973ad70fe2834c825f6140d0601a.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/scene/demo09_canvas/canvas.tscn b/scene/demo09_canvas/canvas.tscn new file mode 100644 index 0000000..0d48930 --- /dev/null +++ b/scene/demo09_canvas/canvas.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bf4xggr34p3fc"] + +[ext_resource type="Script" path="res://scene/demo09_canvas/script/canvas.gd" id="1_h0p4c"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_h0p4c") diff --git a/scene/demo09_canvas/script/canvas.gd b/scene/demo09_canvas/script/canvas.gd new file mode 100644 index 0000000..dfc7513 --- /dev/null +++ b/scene/demo09_canvas/script/canvas.gd @@ -0,0 +1,49 @@ +extends Node2D + + +var whiteColor: Color = Color(1,1,1,1) + +# For Draw_Circle +var circleRadius: float = 10 + +# For Draw_Multiline +var array: Array = [Vector2(200,300),Vector2(300,400),Vector2(300,400),Vector2(400,300)] + +var multiLine: PackedVector2Array = PackedVector2Array(array) + +# For Draw_Rect +var rect: Rect2 = Rect2(200.0,300.0, 200.0,200.0) + +# For Draw_Primitive +var pointsArray: PackedVector2Array = PackedVector2Array([Vector2(700,100),Vector2(800,150),Vector2(900,100)]) +var colorArray: PackedColorArray = PackedColorArray([Color(1,1,1,1),Color(1,1,1,1),Color(1,1,1,1)]) + +# For Draw_String + +var dynamic_font = preload("res://scene/demo09_canvas/BarlowCondensed-Bold.ttf") + +var texture: Texture = null + +func _ready() -> void: + texture = load("res://icon.svg") + +var count = 0 + +func _draw() -> void: + print("start drawing") + draw_circle(Vector2(100,100), circleRadius, whiteColor) + draw_line(Vector2(0,0),Vector2(100,100),whiteColor) + draw_multiline(multiLine, whiteColor) + draw_rect(rect, whiteColor, false) # filled is false + draw_primitive(pointsArray,colorArray, pointsArray) + draw_string(dynamic_font, Vector2(600,500), 'I draw good!') + if count >= 90: + draw_texture(texture, Vector2(400,400)) +# For Draw_String + + +func _process(delta): + count += 1 + if count == 90: + # draw_texture(texture, Vector2(400,400)) + queue_redraw() diff --git a/scene/demo10_animation/animation.tscn b/scene/demo10_animation/animation.tscn new file mode 100644 index 0000000..0339ebf --- /dev/null +++ b/scene/demo10_animation/animation.tscn @@ -0,0 +1,182 @@ +[gd_scene load_steps=20 format=3 uid="uid://0m7gwx6kggro"] + +[ext_resource type="Texture2D" uid="uid://do4b3hpflfwi1" path="res://scene/demo10_animation/image/player.png" id="1_s2byb"] +[ext_resource type="Script" path="res://scene/demo10_animation/script/timer_animation.gd" id="2_moa6m"] +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="3_eunem"] +[ext_resource type="Script" path="res://scene/demo10_animation/script/tween_animation.gd" id="4_ih3vw"] +[ext_resource type="Texture2D" uid="uid://cdcpww682ywng" path="res://scene/demo10_animation/image/run-1.png" id="5_vwedp"] +[ext_resource type="Texture2D" uid="uid://chsdpv60jcl58" path="res://scene/demo10_animation/image/run-2.png" id="6_2xnpv"] +[ext_resource type="Texture2D" uid="uid://dwbbk8etvj2nd" path="res://scene/demo10_animation/image/run-3.png" id="7_ev8ek"] +[ext_resource type="Texture2D" uid="uid://bt3r7fvye3ctd" path="res://scene/demo10_animation/image/run-4.png" id="8_puipc"] +[ext_resource type="Texture2D" uid="uid://d1gtcor5h4js5" path="res://scene/demo10_animation/image/run-5.png" id="9_i5m5b"] +[ext_resource type="Texture2D" uid="uid://dmh8knrjxc8f1" path="res://scene/demo10_animation/image/run-6.png" id="10_6ea7i"] +[ext_resource type="Texture2D" uid="uid://gs5kwcor331o" path="res://scene/demo10_animation/image/run-7.png" id="11_shxe3"] +[ext_resource type="Texture2D" uid="uid://c2eu47l1mjehx" path="res://scene/demo10_animation/image/run-8.png" id="12_7ilo7"] + +[sub_resource type="Animation" id="Animation_hax8x"] +resource_name = "player" +length = 5.0 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 1, 1.6, 2.4, 3.6, 5), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1), +"update": 0, +"values": [Vector2(89, 266), Vector2(263, 211), Vector2(398, 174), Vector2(635, 258), Vector2(978, 391), Vector2(1106, 63)] +} + +[sub_resource type="Animation" id="Animation_grv05"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector2(89, 266)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_i700a"] +_data = { +"RESET": SubResource("Animation_grv05"), +"player": SubResource("Animation_hax8x") +} + +[sub_resource type="Animation" id="Animation_gpqtf"] +resource_name = "player" +length = 0.5 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1), +"update": 1, +"values": [0, 1, 2, 3, 4] +} + +[sub_resource type="Animation" id="Animation_3c1s5"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_67fo3"] +_data = { +"RESET": SubResource("Animation_3c1s5"), +"player": SubResource("Animation_gpqtf") +} + +[sub_resource type="SpriteFrames" id="SpriteFrames_txsbt"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("5_vwedp") +}, { +"duration": 1.0, +"texture": ExtResource("6_2xnpv") +}, { +"duration": 1.0, +"texture": ExtResource("7_ev8ek") +}, { +"duration": 1.0, +"texture": ExtResource("8_puipc") +}, { +"duration": 1.0, +"texture": ExtResource("9_i5m5b") +}, { +"duration": 1.0, +"texture": ExtResource("10_6ea7i") +}, { +"duration": 1.0, +"texture": ExtResource("11_shxe3") +}, { +"duration": 1.0, +"texture": ExtResource("12_7ilo7") +}], +"loop": true, +"name": &"default", +"speed": 10.0 +}] + +[node name="Node2D" type="Node2D"] + +[node name="Animation_1" type="Node2D" parent="."] +position = Vector2(74, 45) +metadata/_edit_group_ = true + +[node name="Sprite2D" type="Sprite2D" parent="Animation_1"] +scale = Vector2(2, 2) +texture = ExtResource("1_s2byb") +hframes = 60 +script = ExtResource("2_moa6m") + +[node name="Timer" type="Timer" parent="Animation_1/Sprite2D"] +wait_time = 0.1 +autostart = true + +[node name="Animation_2" type="Node2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Animation_2"] +position = Vector2(85, 134) +scale = Vector2(0.5, 0.5) +texture = ExtResource("3_eunem") +script = ExtResource("4_ih3vw") + +[node name="Animation_3" type="Node2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Animation_3"] +position = Vector2(89, 266) +scale = Vector2(0.5, 0.5) +texture = ExtResource("3_eunem") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="Animation_3"] +libraries = { +"": SubResource("AnimationLibrary_i700a") +} +autoplay = "player" + +[node name="Animation_4" type="Node2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Animation_4"] +position = Vector2(89, 396) +scale = Vector2(2, 2) +texture = ExtResource("1_s2byb") +hframes = 60 + +[node name="AnimationPlayer" type="AnimationPlayer" parent="Animation_4"] +libraries = { +"": SubResource("AnimationLibrary_67fo3") +} +autoplay = "player" + +[node name="Animation_5" type="Node2D" parent="."] + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Animation_5"] +position = Vector2(96, 537) +sprite_frames = SubResource("SpriteFrames_txsbt") +autoplay = "default" + +[connection signal="timeout" from="Animation_1/Sprite2D/Timer" to="Animation_1/Sprite2D" method="_on_timer_timeout"] diff --git a/scene/demo10_animation/image/player.png b/scene/demo10_animation/image/player.png new file mode 100644 index 0000000..6c7ff1b Binary files /dev/null and b/scene/demo10_animation/image/player.png differ diff --git a/scene/demo10_animation/image/player.png.import b/scene/demo10_animation/image/player.png.import new file mode 100644 index 0000000..3b45ce6 --- /dev/null +++ b/scene/demo10_animation/image/player.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://do4b3hpflfwi1" +path="res://.godot/imported/player.png-e28fee2dde34564549f6b47bedcbb62e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/player.png" +dest_files=["res://.godot/imported/player.png-e28fee2dde34564549f6b47bedcbb62e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-1.png b/scene/demo10_animation/image/run-1.png new file mode 100644 index 0000000..23d6bc8 Binary files /dev/null and b/scene/demo10_animation/image/run-1.png differ diff --git a/scene/demo10_animation/image/run-1.png.import b/scene/demo10_animation/image/run-1.png.import new file mode 100644 index 0000000..f953d59 --- /dev/null +++ b/scene/demo10_animation/image/run-1.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cdcpww682ywng" +path="res://.godot/imported/run-1.png-3280c05cb0e4f0094bf9a065f1c420ed.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-1.png" +dest_files=["res://.godot/imported/run-1.png-3280c05cb0e4f0094bf9a065f1c420ed.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-2.png b/scene/demo10_animation/image/run-2.png new file mode 100644 index 0000000..9c8e2f3 Binary files /dev/null and b/scene/demo10_animation/image/run-2.png differ diff --git a/scene/demo10_animation/image/run-2.png.import b/scene/demo10_animation/image/run-2.png.import new file mode 100644 index 0000000..d8e352f --- /dev/null +++ b/scene/demo10_animation/image/run-2.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://chsdpv60jcl58" +path="res://.godot/imported/run-2.png-c6dd0e2a0fd44ecce64d51822fe106eb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-2.png" +dest_files=["res://.godot/imported/run-2.png-c6dd0e2a0fd44ecce64d51822fe106eb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-3.png b/scene/demo10_animation/image/run-3.png new file mode 100644 index 0000000..d001234 Binary files /dev/null and b/scene/demo10_animation/image/run-3.png differ diff --git a/scene/demo10_animation/image/run-3.png.import b/scene/demo10_animation/image/run-3.png.import new file mode 100644 index 0000000..178db73 --- /dev/null +++ b/scene/demo10_animation/image/run-3.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dwbbk8etvj2nd" +path="res://.godot/imported/run-3.png-a7f3ee534265c5117fb56b89486b5e55.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-3.png" +dest_files=["res://.godot/imported/run-3.png-a7f3ee534265c5117fb56b89486b5e55.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-4.png b/scene/demo10_animation/image/run-4.png new file mode 100644 index 0000000..8e9b71b Binary files /dev/null and b/scene/demo10_animation/image/run-4.png differ diff --git a/scene/demo10_animation/image/run-4.png.import b/scene/demo10_animation/image/run-4.png.import new file mode 100644 index 0000000..889ad23 --- /dev/null +++ b/scene/demo10_animation/image/run-4.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bt3r7fvye3ctd" +path="res://.godot/imported/run-4.png-5f322ba121a10ba33f069dd9c25a1035.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-4.png" +dest_files=["res://.godot/imported/run-4.png-5f322ba121a10ba33f069dd9c25a1035.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-5.png b/scene/demo10_animation/image/run-5.png new file mode 100644 index 0000000..cbc8ed2 Binary files /dev/null and b/scene/demo10_animation/image/run-5.png differ diff --git a/scene/demo10_animation/image/run-5.png.import b/scene/demo10_animation/image/run-5.png.import new file mode 100644 index 0000000..6908ec1 --- /dev/null +++ b/scene/demo10_animation/image/run-5.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d1gtcor5h4js5" +path="res://.godot/imported/run-5.png-6dc8b7d6582a966a0b43c5375057d646.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-5.png" +dest_files=["res://.godot/imported/run-5.png-6dc8b7d6582a966a0b43c5375057d646.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-6.png b/scene/demo10_animation/image/run-6.png new file mode 100644 index 0000000..a05818d Binary files /dev/null and b/scene/demo10_animation/image/run-6.png differ diff --git a/scene/demo10_animation/image/run-6.png.import b/scene/demo10_animation/image/run-6.png.import new file mode 100644 index 0000000..144b3f3 --- /dev/null +++ b/scene/demo10_animation/image/run-6.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dmh8knrjxc8f1" +path="res://.godot/imported/run-6.png-af2f504c10c840072a12547b0a3c767b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-6.png" +dest_files=["res://.godot/imported/run-6.png-af2f504c10c840072a12547b0a3c767b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-7.png b/scene/demo10_animation/image/run-7.png new file mode 100644 index 0000000..c0848b4 Binary files /dev/null and b/scene/demo10_animation/image/run-7.png differ diff --git a/scene/demo10_animation/image/run-7.png.import b/scene/demo10_animation/image/run-7.png.import new file mode 100644 index 0000000..68a9dc3 --- /dev/null +++ b/scene/demo10_animation/image/run-7.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://gs5kwcor331o" +path="res://.godot/imported/run-7.png-778e3a530cfcb29ce7258e12c61126fb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-7.png" +dest_files=["res://.godot/imported/run-7.png-778e3a530cfcb29ce7258e12c61126fb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/image/run-8.png b/scene/demo10_animation/image/run-8.png new file mode 100644 index 0000000..7fa8fe4 Binary files /dev/null and b/scene/demo10_animation/image/run-8.png differ diff --git a/scene/demo10_animation/image/run-8.png.import b/scene/demo10_animation/image/run-8.png.import new file mode 100644 index 0000000..824b536 --- /dev/null +++ b/scene/demo10_animation/image/run-8.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c2eu47l1mjehx" +path="res://.godot/imported/run-8.png-3d745ba5b7d037dda1ae54f02d2b148c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo10_animation/image/run-8.png" +dest_files=["res://.godot/imported/run-8.png-3d745ba5b7d037dda1ae54f02d2b148c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo10_animation/script/timer_animation.gd b/scene/demo10_animation/script/timer_animation.gd new file mode 100644 index 0000000..bad852f --- /dev/null +++ b/scene/demo10_animation/script/timer_animation.gd @@ -0,0 +1,9 @@ +extends Sprite2D + + +func _on_timer_timeout(): + if frame < 5: + frame += 1 + else: + frame = 0 + pass diff --git a/scene/demo10_animation/script/tween_animation.gd b/scene/demo10_animation/script/tween_animation.gd new file mode 100644 index 0000000..e11df8f --- /dev/null +++ b/scene/demo10_animation/script/tween_animation.gd @@ -0,0 +1,12 @@ +extends Sprite2D + + +var tween: Tween = null; +var targetPosition = null + + +func _ready(): + tween = create_tween() + tween.set_loops() + # 会在起始点和终点不断的插值计算 + tween.tween_property(self, "position", Vector2.RIGHT * 300, 1).as_relative().set_trans(Tween.TRANS_SINE) diff --git a/scene/demo11_particle_light/image/white_square.png b/scene/demo11_particle_light/image/white_square.png new file mode 100644 index 0000000..45cdbe5 Binary files /dev/null and b/scene/demo11_particle_light/image/white_square.png differ diff --git a/scene/demo11_particle_light/image/white_square.png.import b/scene/demo11_particle_light/image/white_square.png.import new file mode 100644 index 0000000..073da05 --- /dev/null +++ b/scene/demo11_particle_light/image/white_square.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c7gp2gicvrsyx" +path="res://.godot/imported/white_square.png-1bf12a3951ac2e8d713316b3f8f54ac1.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/image/white_square.png" +dest_files=["res://.godot/imported/white_square.png-1bf12a3951ac2e8d713316b3f8f54ac1.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/light.tscn b/scene/demo11_particle_light/light.tscn new file mode 100644 index 0000000..1cbab0a --- /dev/null +++ b/scene/demo11_particle_light/light.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=2 format=3 uid="uid://bxg5bb58pw3ws"] + +[ext_resource type="Texture2D" uid="uid://c7gp2gicvrsyx" path="res://scene/demo11_particle_light/image/white_square.png" id="1_6vp7i"] + +[node name="Node2D" type="Node2D"] + +[node name="Sprite1" type="Sprite2D" parent="."] +modulate = Color(0.176471, 0.384314, 0.396078, 1) +position = Vector2(212, 153) +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_6vp7i") + +[node name="Sprite2" type="Sprite2D" parent="."] +modulate = Color(0.423529, 0.32549, 0.227451, 1) +position = Vector2(536, 149) +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_6vp7i") + +[node name="Sprite3" type="Sprite2D" parent="."] +modulate = Color(0.588235, 0.168627, 0.278431, 1) +position = Vector2(859, 148) +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_6vp7i") + +[node name="PointLight2D" type="PointLight2D" parent="."] +position = Vector2(539, 246) +scale = Vector2(3.10667, 0.51) +texture = ExtResource("1_6vp7i") diff --git a/scene/demo11_particle_light/normal_map.tscn b/scene/demo11_particle_light/normal_map.tscn new file mode 100644 index 0000000..05ea1a8 --- /dev/null +++ b/scene/demo11_particle_light/normal_map.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=5 format=3 uid="uid://g84n03stjs4g"] + +[ext_resource type="Texture2D" uid="uid://bmspbq66hasqu" path="res://scene/demo11_particle_light/normal_map/azagaya.png" id="1_v4erc"] +[ext_resource type="Texture2D" uid="uid://dgkurote0ib1k" path="res://scene/demo11_particle_light/normal_map/azagaya_n.png" id="2_cebln"] +[ext_resource type="Texture2D" uid="uid://cc1ix37wtungx" path="res://scene/demo11_particle_light/normal_map/LightSprite.png" id="3_56yy5"] + +[sub_resource type="CanvasTexture" id="CanvasTexture_3p7d6"] +diffuse_texture = ExtResource("1_v4erc") +normal_texture = ExtResource("2_cebln") + +[node name="Node2D" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +position = Vector2(306, 192) +texture = SubResource("CanvasTexture_3p7d6") + +[node name="PointLight2D" type="PointLight2D" parent="."] +position = Vector2(382, 169) +texture = ExtResource("3_56yy5") diff --git a/scene/demo11_particle_light/normal_map/LightSprite.png b/scene/demo11_particle_light/normal_map/LightSprite.png new file mode 100644 index 0000000..b5b04d7 Binary files /dev/null and b/scene/demo11_particle_light/normal_map/LightSprite.png differ diff --git a/scene/demo11_particle_light/normal_map/LightSprite.png.import b/scene/demo11_particle_light/normal_map/LightSprite.png.import new file mode 100644 index 0000000..f28397f --- /dev/null +++ b/scene/demo11_particle_light/normal_map/LightSprite.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cc1ix37wtungx" +path="res://.godot/imported/LightSprite.png-c40d01886f4a6ec8b4377142d643177e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/normal_map/LightSprite.png" +dest_files=["res://.godot/imported/LightSprite.png-c40d01886f4a6ec8b4377142d643177e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/normal_map/azagaya.png b/scene/demo11_particle_light/normal_map/azagaya.png new file mode 100644 index 0000000..355c8dc Binary files /dev/null and b/scene/demo11_particle_light/normal_map/azagaya.png differ diff --git a/scene/demo11_particle_light/normal_map/azagaya.png.import b/scene/demo11_particle_light/normal_map/azagaya.png.import new file mode 100644 index 0000000..33e893c --- /dev/null +++ b/scene/demo11_particle_light/normal_map/azagaya.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bmspbq66hasqu" +path="res://.godot/imported/azagaya.png-ad429dd9403620b051e8578587d08aea.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/normal_map/azagaya.png" +dest_files=["res://.godot/imported/azagaya.png-ad429dd9403620b051e8578587d08aea.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/normal_map/azagaya_n.png b/scene/demo11_particle_light/normal_map/azagaya_n.png new file mode 100644 index 0000000..5a506f4 Binary files /dev/null and b/scene/demo11_particle_light/normal_map/azagaya_n.png differ diff --git a/scene/demo11_particle_light/normal_map/azagaya_n.png.import b/scene/demo11_particle_light/normal_map/azagaya_n.png.import new file mode 100644 index 0000000..e7f4ba3 --- /dev/null +++ b/scene/demo11_particle_light/normal_map/azagaya_n.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dgkurote0ib1k" +path="res://.godot/imported/azagaya_n.png-5b93a8bb5a6286587518a775b01152a3.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/normal_map/azagaya_n.png" +dest_files=["res://.godot/imported/azagaya_n.png-5b93a8bb5a6286587518a775b01152a3.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/normal_map/simplebrick.png b/scene/demo11_particle_light/normal_map/simplebrick.png new file mode 100644 index 0000000..48a9226 Binary files /dev/null and b/scene/demo11_particle_light/normal_map/simplebrick.png differ diff --git a/scene/demo11_particle_light/normal_map/simplebrick.png.import b/scene/demo11_particle_light/normal_map/simplebrick.png.import new file mode 100644 index 0000000..015270a --- /dev/null +++ b/scene/demo11_particle_light/normal_map/simplebrick.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cyuaotq1vs5pw" +path="res://.godot/imported/simplebrick.png-5e16cb9c113a4ed9a022f89e50a799bc.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/normal_map/simplebrick.png" +dest_files=["res://.godot/imported/simplebrick.png-5e16cb9c113a4ed9a022f89e50a799bc.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/normal_map/simplebrick_n.png b/scene/demo11_particle_light/normal_map/simplebrick_n.png new file mode 100644 index 0000000..345f112 Binary files /dev/null and b/scene/demo11_particle_light/normal_map/simplebrick_n.png differ diff --git a/scene/demo11_particle_light/normal_map/simplebrick_n.png.import b/scene/demo11_particle_light/normal_map/simplebrick_n.png.import new file mode 100644 index 0000000..0a93aa4 --- /dev/null +++ b/scene/demo11_particle_light/normal_map/simplebrick_n.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dfv4k17llxbo6" +path="res://.godot/imported/simplebrick_n.png-b5f5247c3aa4e49d79ccb3dd8d40a42e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scene/demo11_particle_light/normal_map/simplebrick_n.png" +dest_files=["res://.godot/imported/simplebrick_n.png-b5f5247c3aa4e49d79ccb3dd8d40a42e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scene/demo11_particle_light/occlude.tscn b/scene/demo11_particle_light/occlude.tscn new file mode 100644 index 0000000..757e8bb --- /dev/null +++ b/scene/demo11_particle_light/occlude.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=3 format=3 uid="uid://sfmyqojowakw"] + +[ext_resource type="Texture2D" uid="uid://c7gp2gicvrsyx" path="res://scene/demo11_particle_light/image/white_square.png" id="1_3vx8l"] + +[sub_resource type="OccluderPolygon2D" id="OccluderPolygon2D_xu7kt"] +polygon = PackedVector2Array(-142, -142, -150, 146, 154, 148, 148, -154) + +[node name="Node2D" type="Node2D"] + +[node name="Background" type="Sprite2D" parent="."] +modulate = Color(0.105882, 0.215686, 0.254902, 1) +position = Vector2(560, 332) +scale = Vector2(4.27333, 4.27333) +texture = ExtResource("1_3vx8l") + +[node name="Shadow" type="Sprite2D" parent="."] +modulate = Color(0, 0.0156863, 0.180392, 1) +position = Vector2(471, 157) +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_3vx8l") + +[node name="LightOccluder2D" type="LightOccluder2D" parent="Shadow"] +position = Vector2(-10, 0) +occluder = SubResource("OccluderPolygon2D_xu7kt") +occluder_light_mask = 2 + +[node name="PointLight2D" type="PointLight2D" parent="."] +position = Vector2(619, 366) +scale = Vector2(4.56333, 2.77667) +shadow_enabled = true +shadow_item_cull_mask = 2 +texture = ExtResource("1_3vx8l") diff --git a/scene/demo11_particle_light/particle.tscn b/scene/demo11_particle_light/particle.tscn new file mode 100644 index 0000000..33f0858 --- /dev/null +++ b/scene/demo11_particle_light/particle.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=5 format=3 uid="uid://d25tq5jun4vv3"] + +[ext_resource type="Texture2D" uid="uid://c7gp2gicvrsyx" path="res://scene/demo11_particle_light/image/white_square.png" id="1_ux0kf"] + +[sub_resource type="Gradient" id="Gradient_i2rdc"] + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_mu0kg"] +gradient = SubResource("Gradient_i2rdc") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_j8287"] +particle_flag_disable_z = true +direction = Vector3(0, -1, 0) +initial_velocity_max = 882.05 +gravity = Vector3(0, 98, 0) +scale_min = 0.1 +scale_max = 0.3 +color = Color(0.772549, 0.101961, 0.27451, 1) +color_ramp = SubResource("GradientTexture1D_mu0kg") + +[node name="Node2D" type="Node2D"] + +[node name="GPUParticles2D" type="GPUParticles2D" parent="."] +position = Vector2(493, 458) +amount = 60 +process_material = SubResource("ParticleProcessMaterial_j8287") +texture = ExtResource("1_ux0kf") diff --git a/scene/demo12_gui/Source_Han_Sans.ttf b/scene/demo12_gui/Source_Han_Sans.ttf new file mode 100644 index 0000000..ca36cb6 Binary files /dev/null and b/scene/demo12_gui/Source_Han_Sans.ttf differ diff --git a/scene/demo12_gui/Source_Han_Sans.ttf.import b/scene/demo12_gui/Source_Han_Sans.ttf.import new file mode 100644 index 0000000..5a61149 --- /dev/null +++ b/scene/demo12_gui/Source_Han_Sans.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://ck65b3tqyxgh0" +path="res://.godot/imported/Source_Han_Sans.ttf-8639e80c0af22b5c464d63266154e1ce.fontdata" + +[deps] + +source_file="res://scene/demo12_gui/Source_Han_Sans.ttf" +dest_files=["res://.godot/imported/Source_Han_Sans.ttf-8639e80c0af22b5c464d63266154e1ce.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/scene/demo12_gui/gui.tscn b/scene/demo12_gui/gui.tscn new file mode 100644 index 0000000..4572a86 --- /dev/null +++ b/scene/demo12_gui/gui.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=2 format=3 uid="uid://62hau30vrs2h"] + +[ext_resource type="FontFile" uid="uid://ck65b3tqyxgh0" path="res://scene/demo12_gui/Source_Han_Sans.ttf" id="1_vny5y"] + +[node name="Node2D" type="Node2D"] + +[node name="Label" type="Label" parent="."] +offset_left = 166.0 +offset_top = 110.0 +offset_right = 345.0 +offset_bottom = 153.0 +theme_override_fonts/font = ExtResource("1_vny5y") +text = "你好啊" diff --git a/scene/demo13_camera/move_camera.tscn b/scene/demo13_camera/move_camera.tscn new file mode 100644 index 0000000..28dee1f --- /dev/null +++ b/scene/demo13_camera/move_camera.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=3 format=3 uid="uid://0lol8wbfschs"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="2_02wmm"] +[ext_resource type="Script" path="res://scene/demo13_camera/script/move_camera.gd" id="2_lfqsy"] + +[node name="Node2D" type="Node2D"] + +[node name="Sprite1" type="Sprite2D" parent="."] +modulate = Color(0.14902, 1, 0.054902, 1) +position = Vector2(-528, 248) +texture = ExtResource("2_02wmm") + +[node name="Sprite2" type="Sprite2D" parent="."] +modulate = Color(0.67451, 0.211765, 1, 1) +position = Vector2(507, 285) +texture = ExtResource("2_02wmm") + +[node name="Sprite3" type="Sprite2D" parent="."] +modulate = Color(1, 0, 0.768627, 1) +position = Vector2(26, 293) +texture = ExtResource("2_02wmm") +script = ExtResource("2_lfqsy") +metadata/_edit_group_ = true + +[node name="Camera2D" type="Camera2D" parent="Sprite3"] diff --git a/scene/demo13_camera/script/move_camera.gd b/scene/demo13_camera/script/move_camera.gd new file mode 100644 index 0000000..fa2d367 --- /dev/null +++ b/scene/demo13_camera/script/move_camera.gd @@ -0,0 +1,29 @@ +extends Sprite2D + + +# How fast the player will move (pixels/sec). +@export var speed = 400 +# Size of the game window. +var screen_size + + +func _ready(): + screen_size = get_viewport_rect().size + + +func _process(delta): + var velocity = Vector2.ZERO # The player's movement vector. + if Input.is_action_pressed("move_right"): + velocity.x += 1 + if Input.is_action_pressed("move_left"): + velocity.x -= 1 + if Input.is_action_pressed("move_down"): + velocity.y += 1 + if Input.is_action_pressed("move_up"): + velocity.y -= 1 + + if velocity.length() <= 0: + return + + velocity = velocity.normalized() * speed + position += velocity * delta diff --git a/scene/demo13_camera/script/switch_camera.gd b/scene/demo13_camera/script/switch_camera.gd new file mode 100644 index 0000000..0a522ad --- /dev/null +++ b/scene/demo13_camera/script/switch_camera.gd @@ -0,0 +1,55 @@ +extends Node2D + +const StringUtils = preload("res://zfoo/util/StringUtils.gd") + +var camera1: Camera2D +var camera2: Camera2D +var camera3: Camera2D +var camera4: Camera2D + +var timerCounter = 0 + +func _ready() -> void: + camera1 = get_node("Camera2D1") + camera2 = get_node("Camera2D2") + camera3 = get_node("Camera2D3") + camera4 = get_node("Camera2D4") + + +func _physics_process(delta: float) -> void: + timerCounter += 1 + if(timerCounter == 100): + switchCamera1() + if(timerCounter == 200): + switchCamera2() + if(timerCounter == 300): + switchCamera3() + if(timerCounter == 400): + switchCamera4() + timerCounter = 0 + + + +func switchCamera1() -> void: + camera1.make_current() + print("camera1---------------------------") + postionTest() + +func switchCamera2() -> void: + camera2.make_current() + print("camera2---------------------------") + postionTest() + +func switchCamera3() -> void: + camera3.make_current() + print("camera3---------------------------") + postionTest() + +func switchCamera4() -> void: + camera4.make_current() + print("camera4---------------------------") + postionTest() + +func postionTest(): + print(StringUtils.format("全局坐标[{}]", [$Sprite1.global_position])) + print(StringUtils.format("屏幕坐标[{}]", [$Sprite1.get_global_transform_with_canvas()])) diff --git a/scene/demo13_camera/simple_viewport.tscn b/scene/demo13_camera/simple_viewport.tscn new file mode 100644 index 0000000..cd6f64e --- /dev/null +++ b/scene/demo13_camera/simple_viewport.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=3 format=3 uid="uid://df07ssfhn2ml5"] + +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="1_t771k"] +[ext_resource type="Script" path="res://scene/demo13_camera/script/move_camera.gd" id="2_mglxg"] + +[node name="Node2D" type="Node2D"] + +[node name="icon" type="Sprite2D" parent="."] +position = Vector2(249, 158) +texture = ExtResource("1_t771k") + +[node name="Control" type="Control" parent="."] +modulate = Color(0.47451, 1, 1, 1) +layout_mode = 3 +anchors_preset = 0 +offset_left = 636.0 +offset_top = 140.0 +offset_right = 676.0 +offset_bottom = 180.0 +metadata/_edit_group_ = true + +[node name="SubViewportContainer" type="SubViewportContainer" parent="Control"] +layout_mode = 0 +offset_right = 519.0 +offset_bottom = 512.0 + +[node name="SubViewport" type="SubViewport" parent="Control/SubViewportContainer"] +handle_input_locally = false +render_target_update_mode = 4 + +[node name="Sprite2D" type="Sprite2D" parent="Control/SubViewportContainer/SubViewport"] +position = Vector2(100, 100) +texture = ExtResource("1_t771k") +script = ExtResource("2_mglxg") diff --git a/scene/demo13_camera/switch_camera.tscn b/scene/demo13_camera/switch_camera.tscn new file mode 100644 index 0000000..65eae03 --- /dev/null +++ b/scene/demo13_camera/switch_camera.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=3 format=3 uid="uid://cqfcap32ndasf"] + +[ext_resource type="Script" path="res://scene/demo13_camera/script/switch_camera.gd" id="1_h3uuu"] +[ext_resource type="Texture2D" uid="uid://dwduwy3y2vipi" path="res://icon.svg" id="2_2b276"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_h3uuu") + +[node name="Sprite1" type="Sprite2D" parent="."] +modulate = Color(0.14902, 1, 0.054902, 1) +position = Vector2(-528, 248) +texture = ExtResource("2_2b276") + +[node name="Sprite2" type="Sprite2D" parent="."] +modulate = Color(0.67451, 0.211765, 1, 1) +position = Vector2(507, 285) +texture = ExtResource("2_2b276") + +[node name="Sprite3" type="Sprite2D" parent="."] +modulate = Color(1, 0, 0.768627, 1) +position = Vector2(-549, 884) +texture = ExtResource("2_2b276") + +[node name="Sprite4" type="Sprite2D" parent="."] +modulate = Color(0.690196, 0.639216, 0, 1) +position = Vector2(533, 944) +texture = ExtResource("2_2b276") + +[node name="Camera2D1" type="Camera2D" parent="."] +position = Vector2(-512, 300) + +[node name="Camera2D2" type="Camera2D" parent="."] +position = Vector2(512, 300) + +[node name="Camera2D3" type="Camera2D" parent="."] +position = Vector2(-512, 900) + +[node name="Camera2D4" type="Camera2D" parent="."] +position = Vector2(512, 900) diff --git a/scene/demo14_file/file.tscn b/scene/demo14_file/file.tscn new file mode 100644 index 0000000..4ea3370 --- /dev/null +++ b/scene/demo14_file/file.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://c6kba7v68k7in"] + +[ext_resource type="Script" path="res://scene/demo14_file/script/file.gd" id="1_fl63m"] + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_fl63m") diff --git a/scene/demo14_file/script/file.gd b/scene/demo14_file/script/file.gd new file mode 100644 index 0000000..4a790a2 --- /dev/null +++ b/scene/demo14_file/script/file.gd @@ -0,0 +1,33 @@ +extends Node2D + +const TimeUtils = preload("res://zfoo/util/TimeUtils.gd") +const FileUtils = preload("res://zfoo/util/FileUtils.gd") + + +# Dictionary +var content = "hello file!!!" + +# path string +var filePath: String = "user://playerData.txt" + + +func _ready() -> void: + print("Original Data: ", content) + self.loadData() + print("Altered Data: ", content) + + +func saveData() -> void: + FileUtils.writeStringToFile(filePath, content) + + +func loadData() -> void: + content = FileUtils.readFileToString(filePath) + + +# 退出的时候回调 +func _notification(what): + if what == NOTIFICATION_WM_CLOSE_REQUEST: + content = content + str(TimeUtils.currentTimeMillis()) + self.saveData() + get_tree().quit() # quitting the game diff --git a/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3 b/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3 new file mode 100644 index 0000000..242b631 Binary files /dev/null and b/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3 differ diff --git a/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3.import b/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3.import new file mode 100644 index 0000000..45255ac --- /dev/null +++ b/scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://wmmnatovgd36" +path="res://.godot/imported/Follow Me - Andrew Langdon.mp3-208cd3bb30a229567f90fba5350fdc21.mp3str" + +[deps] + +source_file="res://scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3" +dest_files=["res://.godot/imported/Follow Me - Andrew Langdon.mp3-208cd3bb30a229567f90fba5350fdc21.mp3str"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/scene/demo15_audio/audio1.tscn b/scene/demo15_audio/audio1.tscn new file mode 100644 index 0000000..e4d5e8d --- /dev/null +++ b/scene/demo15_audio/audio1.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=2 format=3 uid="uid://dqfkyrca8rltq"] + +[ext_resource type="AudioStream" uid="uid://wmmnatovgd36" path="res://scene/demo15_audio/audio/Follow Me - Andrew Langdon.mp3" id="1_cbpyw"] + +[node name="Audio1" type="Node2D"] + +[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource("1_cbpyw") +autoplay = true diff --git a/scene/demo16_http/http.tscn b/scene/demo16_http/http.tscn new file mode 100644 index 0000000..f8af9ec --- /dev/null +++ b/scene/demo16_http/http.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://dj6nuhowb41ul"] + +[ext_resource type="Script" path="res://scene/demo16_http/script/httpRequest.gd" id="1_c5eg4"] + +[node name="Node2D" type="Node2D"] + +[node name="HTTPRequest" type="HTTPRequest" parent="."] +script = ExtResource("1_c5eg4") + +[connection signal="request_completed" from="HTTPRequest" to="HTTPRequest" method="_on_request_completed"] diff --git a/scene/demo16_http/script/httpRequest.gd b/scene/demo16_http/script/httpRequest.gd new file mode 100644 index 0000000..7213d49 --- /dev/null +++ b/scene/demo16_http/script/httpRequest.gd @@ -0,0 +1,23 @@ +extends HTTPRequest + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + httpRequest() + pass + +func httpRequest(): + var headers: Array[String] = [] + self.set_use_threads(true) + self.connect("request_completed", Callable(self, "doSomething")) + self.request("https://www.baidu.com/") + + +func doSomething(result, response_code, headers, body: PackedByteArray): + + if(response_code == 200): + var data = body.get_string_from_utf8() + print(data) + else: + print('response_code: ', response_code) + print('problem on the server') diff --git a/zfoo/util/ArrayUtils.gd b/zfoo/util/ArrayUtils.gd new file mode 100644 index 0000000..2fd3cd7 --- /dev/null +++ b/zfoo/util/ArrayUtils.gd @@ -0,0 +1,5 @@ +extends Object + + +static func isEmpty(array: Array) -> bool: + return array == null or array.size() == 0 diff --git a/zfoo/util/FileUtils.gd b/zfoo/util/FileUtils.gd new file mode 100644 index 0000000..e8b70c0 --- /dev/null +++ b/zfoo/util/FileUtils.gd @@ -0,0 +1,38 @@ +extends Object + +const StringUtils = preload("res://zfoo/util/StringUtils.gd") + +# 以追加的方式写入一个content +static func writeStringToFile(filePath: String, content: String) -> void: + var file = FileAccess.open(filePath, FileAccess.WRITE) + # bread and butter + file.store_string(content) + file = null + pass + + +# 读取文件 +static func readFileToString(filePath: String) -> String: + # make sure our file exists on users system + if !FileAccess.file_exists(filePath): + return StringUtils.EMPTY + + # allow reading only for file + var file = FileAccess.open(filePath, FileAccess.READ) + + var content = file.get_as_text() + file = null + return content + +# 读取文件 +static func readFileToByteArray(filePath: String) -> PackedByteArray: + # make sure our file exists on users system + if !FileAccess.file_exists(filePath): + return PackedByteArray() + + # allow reading only for file + var file = FileAccess.open(filePath, FileAccess.READ) + + var buffer = file.get_buffer(file.get_length()) + file = null + return buffer diff --git a/zfoo/util/NodeUtils.gd b/zfoo/util/NodeUtils.gd new file mode 100644 index 0000000..013613f --- /dev/null +++ b/zfoo/util/NodeUtils.gd @@ -0,0 +1,36 @@ +extends Object + +const StringUtils = preload("res://zfoo/util/StringUtils.gd") + +# 移除node节点 +static func removeNode(node: Node) -> void: + if (node == null): + return + var parent = node.get_parent() + if (parent == null): + node.queue_free() + return + parent.remove_child(node) + node.queue_free() + pass + + +# 实例化场景,并将场景添加到node中 +static func addScene(node: Node, scene: PackedScene) -> Node: + var sceneNode = scene.instantiate() + node.add_child(sceneNode) + return sceneNode + +# 转换场景 +static func changeScene(sceneTree: SceneTree, scenePath: String) -> void: + var error = sceneTree.change_scene_to_file(scenePath) + if error != OK: + printerr(StringUtils.format("SceneTree[{}]加载场景[scenePath:{}]异常[{}]", [sceneTree, scenePath, error])) + pass + + +static func changeSceneTo(sceneTree: SceneTree, scene: PackedScene) -> void: + var error = sceneTree.change_scene_to_packed(scene) + if error != OK: + printerr(StringUtils.format("SceneTree[{}]加载场景[scene:{}]异常[{}]", [sceneTree, scene, error])) + pass diff --git a/zfoo/util/StringUtils.gd b/zfoo/util/StringUtils.gd new file mode 100644 index 0000000..f173916 --- /dev/null +++ b/zfoo/util/StringUtils.gd @@ -0,0 +1,28 @@ +extends Object + +const ArrayUtils = preload("res://zfoo/util/ArrayUtils.gd") + +const EMPTY: String = "" +const EMPTY_JSON: String = "{}" + +# Checks if a String is empty ("") or null +static func isEmpty(s: String) -> bool: + return s == null or s.length() == 0 + + +# 检查是否为空的字符串 +static func isBlank(s: String) -> bool: + if isEmpty(s): + return true + + if isEmpty(s.strip_edges(true, true)): + return true + + return false + +# 格式化字符串 +static func format(template: String, args: Array) -> String: + if isEmpty(template) or ArrayUtils.isEmpty(args): + return template + return template.format(args, EMPTY_JSON) + diff --git a/zfoo/util/TimeUtils.gd b/zfoo/util/TimeUtils.gd new file mode 100644 index 0000000..a324768 --- /dev/null +++ b/zfoo/util/TimeUtils.gd @@ -0,0 +1,32 @@ +extends Object + + +# 一秒钟对应的纳秒数 +const NANO_PER_SECOND: int = 1_000_000_000 +# 一秒钟对应的毫秒数 +const MILLIS_PER_SECOND: int = 1 * 1000 +# 一分钟对应的毫秒数 +const MILLIS_PER_MINUTE = 1 * 60 * MILLIS_PER_SECOND +# 一个小时对应的毫秒数 +const MILLIS_PER_HOUR = 1 * 60 * MILLIS_PER_MINUTE +# 8个小时对应的毫秒数 +const MILLIS_PER_HOUR_8 = 8 * 60 * MILLIS_PER_MINUTE +# 一天对应的毫秒数 +const MILLIS_PER_DAY = 1 * 24 * MILLIS_PER_HOUR +# 一周对应的毫秒数 +const MILLIS_PER_WEEK = 1 * 7 * MILLIS_PER_HOUR + + + +# 获取精确的时间戳,单位为毫秒 +static func currentTimeMillis() -> int: + return (Time.get_unix_time_from_system() * MILLIS_PER_SECOND) as int + + +static func timeToString(timestamp: int) -> String: + @warning_ignore("integer_division") + return Time.get_datetime_string_from_unix_time((timestamp + MILLIS_PER_HOUR_8) / MILLIS_PER_SECOND, true) + +static func timeToDateString(timestamp: int) -> String: + @warning_ignore("integer_division") + return Time.get_date_string_from_unix_time((timestamp + MILLIS_PER_HOUR_8) / MILLIS_PER_SECOND)