godotengine / godotengine/godot
The speed and loop properties did not take effect when converting the sprite image to SpriteFrames object and saving it
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Godot_v4.3-stable_win64
### System information
window10
### Issue description
The speed and loop properties did not take effect when converting the sprite image to SpriteFrames object and saving it
### Steps to reproduce
```gdscript
func generate_animations(model_dictionary, save_path, animation_name):
var groupDic: Dictionary = {}
for filename in model_dictionary:
var sp = filename.split("_")
groupDic[sp[1]] = 1
var sprite_frames = SpriteFrames.new()
sprite_frames.remove_animation("default")
for direction in groupDic.keys():
var animation_direction = animation_name + "_" + direction
var texture_arr = file_helper.get_atlas_texture_by_prefix(animation_direction, model_dictionary)
sprite_frames.add_animation(animation_direction)
if texture_arr.size() > 0:
sprite_frames.set_animation_speed(animation_direction, texture_arr.size()/3 )
else:
print("No frames found for animation direction: " + animation_direction)
var loop:bool = false
if animation_name == "stand" || animation_name == "walk":
loop = true
sprite_frames.set_animation_loop(animation_direction,loop)
for texture in texture_arr:
sprite_frames.add_frame(animation_direction, texture)
# save
var result = ResourceSaver.save(sprite_frames, save_path + "/" + animation_name + ".tres", ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS)
print(str(result))
# debug
for anim_name in sprite_frames.get_animation_names():
print("Animation: " + anim_name + ", Speed: " + str(sprite_frames.get_animation_speed(anim_name)) + ", Loop: " + str(sprite_frames.get_animation_loop(anim_name)))
```
### Minimal reproduction project (MRP)
```gdscript
func generate_animations(model_dictionary, save_path, animation_name):
var groupDic: Dictionary = {}
for filename in model_dictionary:
var sp = filename.split("_")
groupDic[sp[1]] = 1
var sprite_frames = SpriteFrames.new()
sprite_frames.remove_animation("default")
for direction in groupDic.keys():
var animation_direction = animation_name + "_" + direction
var texture_arr = file_helper.get_atlas_texture_by_prefix(animation_direction, model_dictionary)
sprite_frames.add_animation(animation_direction)
if texture_arr.size() > 0:
sprite_frames.set_animation_speed(animation_direction, texture_arr.size()/3 )
else:
print("No frames found for animation direction: " + animation_direction)
var loop:bool = false
if animation_name == "stand" || animation_name == "walk":
loop = true
sprite_frames.set_animation_loop(animation_direction,loop)
for texture in texture_arr:
sprite_frames.add_frame(animation_direction, texture)
# save
var result = ResourceSaver.save(sprite_frames, save_path + "/" + animation_name + ".tres", ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS)
print(str(result))
# debug
for anim_name in sprite_frames.get_animation_names():
print("Animation: " + anim_name + ", Speed: " + str(sprite_frames.get_animation_speed(anim_name)) + ", Loop: " + str(sprite_frames.get_animation_loop(anim_name)))
```
_Bugsquad edit:_ Fix codeblock formatting.
Contributor guide
Assessment
This issue has not been assessed yet.