pull/2/head
jaysunxiao 2021-10-04 16:49:12 +08:00
parent d1601a3e54
commit 371b509691
18 changed files with 273 additions and 1 deletions

View File

@ -20,6 +20,8 @@
![Image text](image/gc2.png) ![Image text](image/gc2.png)
![Image text](image/gc3.png) ![Image text](image/gc3.png)
- gdscript是垃圾回收和手动回收结合起来了使用什么样的回收完全交给你自己
![Image text](image/太极.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/太极.png-59d7111e2abf9f43bec4eb921f3e6540.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://doc/demo02_base/image/太极.png"
dest_files=[ "res://.import/太极.png-59d7111e2abf9f43bec4eb921f3e6540.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -17,6 +17,16 @@ unity的2d坐标系虽然在左下角但是unity的屏幕坐标系依然在
因为单论平面内容制作左上原点更符合视觉习惯也更符合设计常识比如ps。 因为单论平面内容制作左上原点更符合视觉习惯也更符合设计常识比如ps。
``` ```
# 全局坐标和局部坐标(相对坐标)
- 全局坐标和局部坐标可以相互转化
```
Node2D及其子节点的位置可以使用position和gloabl_position来控制其中前者是该节点相对于父节点的相对位置后者是全局位置。
简而言之position的坐标系是以父节点的位置坐标为原点的坐标系方向还是水平向右为x轴正方向竖直向下为y轴正方向。
需要注意的是,全局位置是以场景的左上角为原点的,并不是以根结点的位置作为原点的
```
# 场景和节点 # 场景和节点
![Image text](image/场景.png) ![Image text](image/场景.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/move1.png-95aa6fa257a51da26ff41252e07cc282.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://doc/demo06_move/image/move1.png"
dest_files=[ "res://.import/move1.png-95aa6fa257a51da26ff41252e07cc282.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/move2.png-b5b7532785e6fca5f754677b3a706a98.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://doc/demo06_move/image/move2.png"
dest_files=[ "res://.import/move2.png-b5b7532785e6fca5f754677b3a706a98.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/move3.png-7f98e06376aee3a2f31cf0a02a960d9b.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://doc/demo06_move/image/move3.png"
dest_files=[ "res://.import/move3.png-7f98e06376aee3a2f31cf0a02a960d9b.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

3
doc/demo06_move/move.md Normal file
View File

@ -0,0 +1,3 @@
![Image text](image/move1.png)
![Image text](image/move2.png)
![Image text](image/move3.png)

View File

@ -24,6 +24,41 @@ config/name="godot-util"
run/main_scene="res://scene/demo01_hello/HelloWorld.tscn" run/main_scene="res://scene/demo01_hello/HelloWorld.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[input]
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true

View File

@ -4,6 +4,7 @@
[ext_resource path="res://icon.png" type="Texture" id=2] [ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Node2D" type="Node2D"] [node name="Node2D" type="Node2D"]
position = Vector2( 100, 0 )
[node name="Hero" type="Sprite" parent="."] [node name="Hero" type="Sprite" parent="."]
position = Vector2( 477.791, 270.893 ) position = Vector2( 477.791, 270.893 )

View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://script/demo06_move/move_hero.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Node2D" type="Node2D"]
[node name="MoveHero" type="Sprite" parent="."]
position = Vector2( 492.717, 412.746 )
texture = ExtResource( 2 )
script = ExtResource( 1 )

View File

@ -9,3 +9,5 @@ script = ExtResource( 1 )
[node name="icon" type="Sprite" parent="."] [node name="icon" type="Sprite" parent="."]
position = Vector2( 410.547, 444.333 ) position = Vector2( 410.547, 444.333 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="RigidBody2D" type="RigidBody2D" parent="."]

View File

@ -9,6 +9,21 @@ var spriteHeight: int
func _enter_tree(): func _enter_tree():
# textureTest()
# positionTest()
pass
# 坐标点测试用例
func positionTest():
print(position)
print(global_position)
print(to_global(position))
print(to_local(global_position))
pass
# 纹理测试用例
func textureTest():
var texture = get_texture() var texture = get_texture()
var image = texture.get_data() var image = texture.get_data()
print(offset) print(offset)

View File

@ -0,0 +1,31 @@
extends Sprite
# 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)

26
zfoo/util/IdUtils.gd Normal file
View File

@ -0,0 +1,26 @@
extends Object
const atomicInt: Array = [0]
const mutex = [false, null]
static func getMutex() -> Mutex:
if mutex[0]:
return mutex[1]
var mutexInstance = Mutex.new()
mutex[1] = mutexInstance
return mutexInstance
# 获取本地int的唯一id如果达到最大值则重新从最小值重新计算线程安全
static func getLocalIntId() -> int:
var mutexInstance = getMutex()
mutexInstance.lock()
var id = atomicInt[0]
atomicInt[0] = id + 1
mutexInstance.unlock()
return id