• RuntimesGodot
  • [godot] 我把同样的 .atlas、png、spine-json 放到用户目录下,加载不起作用

[godot] 我把同样的 .atlas、png、spine-json 放到用户目录下,加载不起作用,放在工程目录下是可以的

上面正常工作

这个会崩溃

png和atlas是从server上获取的,我想通过网络请求,动态的生成不同的骨骼动画,这个功能应该如何实现?

Related Discussions
...

在 Godot 中,Spine 的 .atlas.png.spine-json 文件需要放在项目目录下才能正常加载。这是因为 Godot 的资源导入系统依赖于项目目录结构来管理和引用资源。如果将这些文件放在用户目录下,Godot 无法正确识别和导入这些资源,从而导致加载失败。

要通过网络请求动态生成不同的骨骼动画,您可以考虑以下步骤:

  1. 下载资源:使用 Godot 的 HTTPRequest 节点从服务器下载 .atlas.png.spine-json 文件到项目目录的某个子目录中。

  2. 导入资源:确保下载的文件在项目目录中,然后 Godot 会自动检测到这些文件并进行导入。如果没有自动导入,您可以在 Godot 编辑器中手动触发导入。

  3. 创建 SpineSkeletonDataResource:在 Godot 中,使用下载的资源创建一个 SpineSkeletonDataResource,并将其分配给 SpineSprite 节点以显示动画。

  4. 更新动画:如果需要更新动画,只需重新下载新的资源并覆盖旧的文件,Godot 会自动重新导入并更新动画。

通过这种方式,您可以动态地从服务器获取和更新 Spine 动画资源。

    Spinebot 我的游戏已经发布运行了,我如何导入到编辑器中呢,请给我正确的解决方案,我需要动态加载

    20 jours plus tard

    Loading from the user:// dir works as intended. I put spineboy-pro.skel and spineboy.atlas/spineboy.png into

    /Users/badlogic/Library/Application Support/Godot/app_userdata/spine-godot-examples/save/animation

    To simulate your setup. spine-godot-examples is the project name. In your case it's DesktopPets.

    I then load the skeleton and atlas via this code:

    extends Node2D
    
    func _ready():
    	# Load the skeleton file
    	var skeleton_file_res = SpineSkeletonFileResource.new();
    	var error = skeleton_file_res.load_from_file("user://save/animation/spineboy-pro.skel");
    	if (error != OK):
    		print("Could not load skeleton")	
    	
    	# Load the atlas file
    	var atlas_res = SpineAtlasResource.new();
    	error = atlas_res.load_from_atlas_file("user://save/animation/spineboy.atlas");
    	if (error != OK):
    		print("Could not load atlas")	
    	
    	# Create a skeleton data resource, you can share this across multiple sprites
    	var skeleton_data_res = SpineSkeletonDataResource.new();
    	skeleton_data_res.skeleton_file_res = skeleton_file_res;
    	skeleton_data_res.atlas_res = atlas_res
    	
    	# Create a sprite from the skeleton data and add it as a child
    	var sprite = SpineSprite.new();
    	sprite.skeleton_data_res = skeleton_data_res;
    	sprite.position.x = 200;
    	sprite.position.y = 200;
    	sprite.get_animation_state().set_animation("walk", true, 0);
    	self.add_child(sprite)
    	pass

    This works as intended.

    I tested this by running the respective scene from within the editor. Indeed, running the scene from a packaged app fails. Investigating.

    The atlas page image loading was broken outside of editor enabled builds. This is now fixed in the latest commit on the 4.2 branch. GitHub actions is building new editor and GDExtension builds. Thanks for reporting!