quimnuss

  • Dec 4, 2024
  • Joined Sep 5, 2023
  • 1 best answer
  • 10 minutes after posting I saw the Animation section of the texture in the debugging :_)

    That has the vframes and frame parameters which is what I needed dang. I've been struggling with this for a while. I got misled by the section title.

    Is it good practice if I use that instead of atlas even thought is not an animation?

  • I couldn't find a comfortable solution for this searching the internet.

    I've made a spritesheet with a dozen sprites of different species and my plan was to use it and select the appropriate region changing just an enum or integer. Similar to what you can do with AnimatedSprites. That way I can use say one button and switch its texture with just changing the int and I don't have to worry about the texture.

    However I haven't found how godot has thought of this. You have the AtlasTexture but setting the region rect is not straightforward in gdscript, and in the editor I have to set the pixel offset every time since I couldn't find a way to establish the sprite "tiles" size of 32x32 and just use ints for selecting the frame I want.

    Most people have one texture per entity so I guess they set it dragging in the editor or loading it and setting it at _ready via some filename naming logic. Seems a bit more convoluted than it ought to be. Or use the atlas selecting the region and store N resources and then code the naming logic (i guess).

    It feels like there should be a godot way of saying this texture is a spritesheet of 32x32 sprites and use the nth sprite

    Maybe you senseis know of a better way of doing this or I might be missing something relevant.

  • I have predator animals that keep track of prey animals. At first I kept them in an array but when one of the prey dies or is eaten I get an invalid element in the predator's prey array, which hints me this is not the way.

    What is the best practices way of storing collections of other nodes to avoid having to clean up?

    1. children nodes

    Prey nodes can't be children of predators since there are many types of predators which share prey.

    1. groups

    That could work if I assign a group for each species, but that's a lot of groups. Is that the appropiate way?
    pick_random from group each time the predator is instructed to hunt.

    1. signal on death/freed

    Since I have to register each new prey to each potential predator at birth, I could also connect the free signal and delete from the array reactivelly.

    1. blackboard

    have a blackboard object each animal registers to. I think this wouldn't be that different to the groups option.

    any more ideas? how would you do it?

    • xyz replied to this.
    • I would use groups. They are just arrays behind the scene, so it's similar to a blackboard, except you don't have to manage it yourself.

    • duane no no they're both 4.1. But I'll check if the basis is diferent, thanks!

    • xyz aaah i see, i scrolled down to read the table of contents, which is the TOC of the udemy course, not the book! I'll definetely check it out

    • xyz I'm interested on good tutorials in python as well! "automate the boring stuff with python" proceeds to not automate any boring task, and basically teach python syntax as usual. I'm interested on finding a good hands-on teaching python courses for our juniors, I did a quick search last year but was left unconvinced. Does anybody have some gold tutorials in mind? Maybe my expectations are unrealistic.

      I love the way tiangolo documents for example. And fowler is another icon.

      • xyz replied to this.
      • What is the state of web export at the moment? There are many issues referencing it being broken in Godot4 but it works on Windows' godot.

        I am now in a linux machine and the option is disabled stating C# export to web is not yet supported and that I should get a non-c# godot if my project doesn't have c# (that's the case)

        What confuses me is that I didn't have to get a specific godot n windows to do this. Do i have to build godot from source in linux or what's the current situation? `

      • synthnostate Yes I could configure up the animation libraries at the animal scene but it's easier to make mistakes, overwrite stuff and harder to not forget steps.

        All this setup is to make it no-code easy to add new species to the mix, I just had to set up a resource with a sprite frames and speed and some other float stats, add it to a global enum, and voilà, you have a new species. Ideally without even opening godot.

        Setting up sprite frames was not ideal but ok, setting up animation libraries is not as straight forward, at that point might be better to create one scene per animal...

        For what I've seen, most projects do that, create one scene per enemy and mostly change float members of the enemy via data. The full data-driven approach I've only seen it for inventories, and since those are not animated they don't have to solve that.

        It's a pity, thought. I wish setting up the animation library would be faster, I might just drop the idea of animal from resource and do one scene per animal.

      • Hm, animation libraries are a bit clunky when moved from one scene to another. More often than not they lose the key reference to the sprite2d and there's no way to reassociate via the editor.

        • A foreach loop might be the piece you're missing:

          for ship in ships:
              if ship.active:
                   return
          reset_turn() --> for ship in ships: ship.active = true

          altho for your use case I would have a copy of the ships array named ships_active and pop them until ships_active.empty()

          at the start of the iteration:
          var ships_active = ships_array
          and then next_ship_to_play = ships_active.pop_back() or something like that depending on your context

          anyway everything depends 🙂

          • The method works. It's more tedious because you have to change the texture, it's dimensions, and then setup the animation library. So it takes a few more steps before you see anything. Also you must not screw up the spritesheet dimensions on the resource.

            All this was included in the sprite frames, but overall it's not that different and the animation library is WAY more powerful, so it will pay off in the long run.

            Plus reusable animation library if the textures were similar enough, but unfortunately not my case.

          • Or would you also key in the sprite2d ctex? I'm not sure about this part

          • synthnostate Nice! Animation Libraries isn't greatly documented, but sounds like on point for what I want to achieve.

            If i guess the full workflow correctly, I have to create each animation track (idle,run,die,eat) for each animal, save it as <animal>_animation_bundle.tres : AnimationLibrary and then on my data resources rabbit_data.tres just set animation_bundle to the animation library resource for that animal. What's cool about this is that I can fine-tune animations if I want.

            Then on _ready, player.add_animation for the 4 animations in animation library. Is there a way to add a whole library to a player? then on _ready, animation_player.add_animation_library("watever", resource.animation_library) Is the spritesheet set as texture of a Sprite2D stored in the track or can I "hot-swap" it on the _ready() and the player track will request the frames to the sprite agnostic to it? What I mean is, is my rabbit resource will have an animation library resource created previously with a specific Sprite2D spritesheet. Do I have to store that Sprite2D spritesheet in the resource or does the animationlibrary also store its keyed nodes somehow? I guess not.

            If not, does that mean that if I have two identically structured spritesheets I could potentially reuse the animation library?

            Ignore the animatedsprite2d called by animation_player, I like the workflow you proposed much better.

          • I have a general Animal scene which sets its particularities on _ready() from a resource file. Up to now, it had name, speed and sprite frames.

            All sprite frames had at least the animations idle, run, eat and die, and then the Animal script just had to call $AnimatedSprite2D.play(state).

            Now I want to switch to AnimationPlayer and I've seen that there's something like Animation Library, but I don't know what would be the recommended way of having the animations as a resource parameter like I had before.

            I've seen you can also play animatedsprite2d's animations in an AnimationPlayer by keying the animation and the first and last frame with interpolation continuous. A quick workaround. The problem with this approach is that I must set the number of frames per animation, because it's not the same for every animal.

            I have seen I can store the animation "montage" of the AnimationPlayer in a *.res file, which I imagine I could recover with animal_resource.animation_track/bundle and then call something like AnimationPlayer.add_track() or something like that, but seems off to do it like this.

            So maybe you Jedis know the standard way of doing this, with the caveat that I might have 100 similar animals, so I really need this resource-based actor approach

            • it worked after exporting without doing anything.

              Misteries...

              • Hopping in too! Got tired of astronomical requirements of the prototype I'm making so jumped in godot for a simpler life 🙂

                • Hi! I've used yafsm addon in a project but it doesn't ship with the binary (tried on windows)

                  Do I have to add the scripts in addons/ explicitly like i do with json?

                  I've installed ga-yafsm via the asset library and when i run the exported game the console complains it can't find the resources under addons/.

                  It's my first export, so I'm a bit lost as to how to fix it and I couldn't find any information on shipping games with addons.