Godot 载入Pck

var pck_path = "mod.pck"
var sprite_frames_path = "res://tres/main_mod.tres"
	if ProjectSettings.load_resource_pack(pck_path):
		print("PCK 加载成功")
		# 从 PCK 文件中加载 SpriteFrames 资源
		var sprite_frames = load(sprite_frames_path)
		if sprite_frames:
			apply_sprite_frames($"../AnimatedSprite2D", sprite_frames)
		else:
			print("无法加载 SpriteFrames 资源")
	else:
		print("无法加载 PCK 文件")
	pass # Replace with function body.
func apply_sprite_frames(animated_sprite: AnimatedSprite2D, sprite_frames: SpriteFrames):
	animated_sprite.frames = sprite_frames
	if sprite_frames.get_animation_names().size() > 0:
		animated_sprite.animation = sprite_frames.get_animation_names()[0]
		animated_sprite.play()
posted @ 2024-10-20 21:12  eva1024  阅读(7)  评论(0编辑  收藏  举报