From dbc72bb2932f5bf886983a6f96ef41ee039d5207 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Sat, 22 Jan 2022 19:12:49 +0800 Subject: [PATCH] doc --- doc/demo05_scene_node/scene_node.md | 20 ++++++++++++++- script/demo05_scene_node/hero.gd | 40 +++++++++++++++-------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/doc/demo05_scene_node/scene_node.md b/doc/demo05_scene_node/scene_node.md index bc2f02c..2b12750 100644 --- a/doc/demo05_scene_node/scene_node.md +++ b/doc/demo05_scene_node/scene_node.md @@ -64,9 +64,27 @@ Node2D及其子节点的位置可以使用position和gloabl_position来控制。 # 4. 基本组件 -- CanvasItem, +- CanvasItem节点,CanvasItem -> Node -> Object +- Canvas是画布的意思,所以CanvasItem代表了就是可以被绘制节点,可以设置可视化界面和材质的颜色 +- 所有的2D节点和GUI节点都继承于CanvasItem节点 ![Image text](./image/component1.png) + + +- Sprite节点,Node2d -> CanvasItem -> Node -> Object +- 用来显示一张图片 ![Image text](./image/component2.png) + + +- Texture类,Resource -> Reference -> Object +- Texture 贴图,附加到物体表面的贴图,实际上就是包含一张Image图片 +- 可以用在3D模型中当作贴图,或者2D的Sprite中当作图片,或者GUI的背景 ![Image text](./image/component3.png) + + +- Image类,Resource -> Reference -> Object +- 包含了图片的数 ![Image text](./image/component4.png) + + +- 总结 ![Image text](./image/component5.png) diff --git a/script/demo05_scene_node/hero.gd b/script/demo05_scene_node/hero.gd index 1f653bd..67859a1 100644 --- a/script/demo05_scene_node/hero.gd +++ b/script/demo05_scene_node/hero.gd @@ -12,8 +12,8 @@ var spriteHeight: int func _enter_tree(): windowPositionTest() - # textureTest() # positionTest() + # textureTest() pass @@ -22,10 +22,9 @@ func windowPositionTest(): print(StringUtils.format("屏幕大小[{}]", [OS.window_size])) print(StringUtils.format("屏幕位置[{}]", [OS.window_position])) + # 设置游戏屏幕的位置 OS.window_position = Vector2(100, 100) # OS.window_fullscreen = true - print(get_global_transform_with_canvas().get_origin()) - print(global_position) pass # 坐标点测试用例 @@ -36,22 +35,6 @@ func positionTest(): print(to_local(global_position)) pass -# 纹理测试用例 -func textureTest(): - var texture = get_texture() - var image = texture.get_data() - print(offset) - print("texture type: ", texture) - print("height: ", texture.get_height()) - print("width: ", texture.get_width()) - print("Image data property: ", image.data) - - # 无法直接编辑图片 - image.shrink_x2() - print("new image data property",image.data) - #这样做会破坏项目的资源,使资源变得混乱 - #image.save_png("C:\\Users\\jaysunxiao\\Desktop\\newImage.png") - func _physics_process(delta): setupSprite() setupGameWindow() @@ -80,3 +63,22 @@ func positionBottomCenter() -> void: func positionLeftCenter() -> void: self.position.x = spriteWidth / 2 self.position.y = gameHeight / 2 + + + +# 纹理测试用例 +func textureTest(): + var texture = get_texture() + var image = texture.get_data() + print(offset) + print("texture type: ", texture) + print("height: ", texture.get_height()) + print("width: ", texture.get_width()) + print("Image data property: ", image.data) + + # 无法直接编辑图片 + image.shrink_x2() + print("new image data property",image.data) + #这样做会破坏项目的资源,使资源变得混乱 + image.save_png("C:\\Users\\jaysunxiao\\Desktop\\newImage.png") + pass