RandomTextureSpriteBehavior: Get path from AtlasTexture.atlas#2221
Merged
manuq merged 1 commit intoMay 19, 2026
Merged
Conversation
This script works by selecting one of an array of SpriteFrames resources
at random, then offsetting the sprite based on information encoded in
the filename. For example, the names of
townie-body_003.dx_-4.dy_-16.tres and its underlying texture atlas
townie-idle-body_003.dx_-4.dy_-16.png encode that the sprite should be
offset by Vector2(-4, -16). This allows different randomly-generated
townies to be different sizes.
We have some code that tries to find the path to the chosen SpriteFrames
resource, or failing that the path of the underlying texture. In practice,
`new_sprite_frames.resource_path.get_file()` is always `""` (for unknown
reasons) so we always use the second path, looking at the path of the
first frame of the idle texture.
Previously this was:
filename = new_sprite_frames.get_frame_texture(&"idle", 0).resource_path
But the behaviour differs between running the game in the editor and in
release builds. In the editor, this gives
`res://scenes/game_elements/characters/components/sprite_frames/townie-legs_002.dy_-6.tres::AtlasTexture_s8pun`,
while in the exported game we get
`res://scenes/game_elements/characters/npcs/townie.tscn::AtlasTexture_s8pun`.
I can't quite explain this but my guess is that the SpriteFrames in
`townie-legs_002.dy_-1.tres` is getting inlined into the exported binary
`townie.scn`. But if we walk one step deeper, resolving the AtlasTexture
to its underlying Texture2D, whose resource_path is
`res://scenes/game_elements/characters/npcs/components/townie-idle-legs_002.dy_-6.png`
as hoped.
Also add a missing .get_file() to convert from the full path to the
filename in this code path.
Resolves #2216
|
Play this branch at https://play.threadbare.game/branches/endlessm/wjt/randomtexturespritebehavior-get-path-from-atlastexture-atlas/. (This launches the game from the start, not directly at the change(s) in this pull request.) |
manuq
approved these changes
May 19, 2026
Collaborator
manuq
left a comment
There was a problem hiding this comment.
Oh awesome, thanks for the fix! I was going to add a dictionary property to map the textures with Vector2 offsets.
Member
Author
|
I was thinking an array of structs: class_name RandomTextureSpriteBehavior
...
class BodyPart extends Resource:
sprite_frames: SpriteFrames
offset: Vector2
@export var sprite_frames: Array[BodyPart]It might still be clearer to do that… but this does work. Or! We could have: class_name BodyPart extends SpriteFrames
@export var offset: Vector2and make |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RandomTextureSpriteBehavior: Get path from AtlasTexture.atlas
This script works by selecting one of an array of SpriteFrames resources
at random, then offsetting the sprite based on information encoded in
the filename. For example, the names of
townie-body_003.dx_-4.dy_-16.tres and its underlying texture atlas
townie-idle-body_003.dx_-4.dy_-16.png encode that the sprite should be
offset by Vector2(-4, -16). This allows different randomly-generated
townies to be different sizes.
We have some code that tries to find the path to the chosen SpriteFrames
resource, or failing that the path of the underlying texture. In practice,
new_sprite_frames.resource_path.get_file()is always""(for unknownreasons) so we always use the second path, looking at the path of the
first frame of the idle texture.
Previously this was:
But the behaviour differs between running the game in the editor and in
release builds. In the editor, this gives
res://scenes/game_elements/characters/components/sprite_frames/townie-legs_002.dy_-6.tres::AtlasTexture_s8pun,while in the exported game we get
res://scenes/game_elements/characters/npcs/townie.tscn::AtlasTexture_s8pun.I can't quite explain this but my guess is that the SpriteFrames in
townie-legs_002.dy_-1.tresis getting inlined into the exported binarytownie.scn. But if we walk one step deeper, resolving the AtlasTextureto its underlying Texture2D, whose resource_path is
res://scenes/game_elements/characters/npcs/components/townie-idle-legs_002.dy_-6.pngas hoped.
Also add a missing .get_file() to convert from the full path to the
filename in this code path.
Resolves #2216