pull/2/head
jaysunxiao 2022-01-22 19:12:49 +08:00
parent 0588b17389
commit dbc72bb293
2 changed files with 40 additions and 20 deletions

View File

@ -64,9 +64,27 @@ Node2D及其子节点的位置可以使用position和gloabl_position来控制。
# 4. 基本组件 # 4. 基本组件
- CanvasItem - CanvasItem节点CanvasItem -> Node -> Object
- Canvas是画布的意思所以CanvasItem代表了就是可以被绘制节点可以设置可视化界面和材质的颜色
- 所有的2D节点和GUI节点都继承于CanvasItem节点
![Image text](./image/component1.png) ![Image text](./image/component1.png)
- Sprite节点Node2d -> CanvasItem -> Node -> Object
- 用来显示一张图片
![Image text](./image/component2.png) ![Image text](./image/component2.png)
- Texture类Resource -> Reference -> Object
- Texture 贴图附加到物体表面的贴图实际上就是包含一张Image图片
- 可以用在3D模型中当作贴图或者2D的Sprite中当作图片或者GUI的背景
![Image text](./image/component3.png) ![Image text](./image/component3.png)
- Image类Resource -> Reference -> Object
- 包含了图片的数
![Image text](./image/component4.png) ![Image text](./image/component4.png)
- 总结
![Image text](./image/component5.png) ![Image text](./image/component5.png)

View File

@ -12,8 +12,8 @@ var spriteHeight: int
func _enter_tree(): func _enter_tree():
windowPositionTest() windowPositionTest()
# textureTest()
# positionTest() # positionTest()
# textureTest()
pass pass
@ -22,10 +22,9 @@ func windowPositionTest():
print(StringUtils.format("屏幕大小[{}]", [OS.window_size])) print(StringUtils.format("屏幕大小[{}]", [OS.window_size]))
print(StringUtils.format("屏幕位置[{}]", [OS.window_position])) print(StringUtils.format("屏幕位置[{}]", [OS.window_position]))
# 设置游戏屏幕的位置
OS.window_position = Vector2(100, 100) OS.window_position = Vector2(100, 100)
# OS.window_fullscreen = true # OS.window_fullscreen = true
print(get_global_transform_with_canvas().get_origin())
print(global_position)
pass pass
# 坐标点测试用例 # 坐标点测试用例
@ -36,22 +35,6 @@ func positionTest():
print(to_local(global_position)) print(to_local(global_position))
pass 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): func _physics_process(delta):
setupSprite() setupSprite()
setupGameWindow() setupGameWindow()
@ -80,3 +63,22 @@ func positionBottomCenter() -> void:
func positionLeftCenter() -> void: func positionLeftCenter() -> void:
self.position.x = spriteWidth / 2 self.position.x = spriteWidth / 2
self.position.y = gameHeight / 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