checheche/Robo-Bus-A31-HMI/common/tool/texture_tool.gd
2024-12-06 21:22:11 +08:00

27 lines
922 B
GDScript

class_name TextureTool
extends Node
static func texture_load(id):
if !Global.texture_data.has(id):return null
if !Global.texture.has(id):
Global.texture[id] = load(Global.texture_data[id].path)
return Global.texture[id]
static func texture_load_arr(id_arr):
var arr = []
for id in id_arr:
arr.append(texture_load(id))
return arr
#图片拆分
static func cropping(texture:Texture2D,frames = Vector2i(1,1),frame_coords = Vector2i(1,1),texute_name = ""):
var key = texute_name + str(frame_coords)
if !Global.texture.has(key):#如果图片不存在就写入
var image = texture.get_image()
var size = image.get_size()
var image_x = size.x / frames.x
var image_y = size.y / frames.y
var post = (Vector2i(frame_coords)*Vector2i(image_x,image_y))
image = image.get_region(Rect2i(post,Vector2i(image_x,image_y)))
Global.texture[key] = ImageTexture.create_from_image(image)
return Global.texture[key]