Texture
以下为我对于官方文档的翻译以及使用情况,3.0版本的文档
Texture官方文档
继承: Resource < Reference < Object
被继承: CurveTexture, AtlasTexture, ProxyTexture, GradientTexture, ViewportTexture, StreamTexture, ImageTexture, LargeTexture
类别: Core
简要说明
2D和3D纹理
成员函数
返回类型 | 函数 |
---|---|
void | draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const |
void | draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const |
void | draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const |
Image | get_data ( ) const |
int | get_height ( ) const |
Vector2 | get_size ( ) const |
int | get_width ( ) const |
bool | has_alpha ( ) const |
成员变量
- int flags - 纹理的样式。
枚举
enum Flags
- FLAGS_DEFAULT = 7 — 默认样式。生成mipmaps,repeat(重复),和 filter(滤镜)被启用。
- FLAG_MIPMAPS = 1 — 生成mipmaps,,它们是缩小时使用的相同纹理的较小版本,保持纵横比。
- FLAG_REPEAT = 2 — 重复纹理(而不是堆到边缘)。
- FLAG_FILTER = 4 — 放大滤镜,使纹理平滑缩放。
- FLAG_ANISOTROPIC_FILTER = 8 — 各向异性mipmap滤波。生成具有不同纵横比的相同纹理的较小版本。
当这些纹理(例如,墙壁或地面)在视口被压扁到不同的纵横比时,能更有效地向平面范围展示,和常规mipmap保持纵横比,因此在这些情况下它们不能很好地优化存储。 - FLAG_CONVERT_TO_LINEAR = 16 — 将纹理转换为SRGB颜色空间。
- FLAG_MIRRORED_REPEAT = 32 — 重复纹理与交替部分镜像。
- FLAG_VIDEO_SURFACE = 4096 — 纹理是一个视频表面。
描述
纹理通过在视频硬件中注册图像来工作,然后可以在3D模型或2D精灵或GUI控件中使用图像。
成员函数描述
-
void draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
-
void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
-
void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const
-
Image get_data ( ) const
-
int get_height ( ) const
返回纹理高度。
- Vector2 get_size ( ) const
返回纹理大小。
- int get_width ( ) const
返回纹理宽度。
- bool has_alpha ( ) const
使用
关于get_height()、get_size()、get_width()的使用。
创建场景。
- Node
- Sprite
- Label
- Button
为根节点添加脚本,连接Button的pressed()信号。
直接将图片冲=从资源栏拖进Sprite节点的Texture属性。
单击属性栏中显示的图片,查看texture的详细信息。
可以看出图片拖进去后,为节点的Texture属性新建一个StreamTexture类的对象,这个StreamTexture类是Texture的子类,那也就继承了父类Texture的函数。
设置下控件位置大小。
为脚本添加代码。
运行下。
查看下图片的属性。