How to use arrays to stock different info (hitbox,sprite sheet/animations)

Godot Version

4.2.1 stable

Question

i’m trying to make a spell system where there’s one node that would manage every spells via an array (i’m not sure if that’s possible i’m just trying some stuff out) rn i managed to make a fireball spawn and move but the thing is that when i try to give it an animation or a hitbox i need to use my array but i don’t really get how that works ?
i tried to use the animated texture 2d to give it an animation but that looks very tedious since you need to put every image frame by frame and i made a sprite sheet for the anim so i’d love to use that instead and also when i try to give it an hit box the shape doesn’t show on screen, i’m not sure what i’m doing wrong since i’m a total beginner.

I’m not entirely certain what your question is, but I assume you want to have different kind of spells inside an array. Like [fire_spell, ice_spell, water_spell]. Here’s some pointers how to get that done:

You might want to make your spell a Resource: You can handily save multiple properties (like texture, power, element or whatever you have) in one tidy package. For example:

class_name MyCustomSpellResource
extends Resource

# Expose these in the inspector:
@export var power : float
@export var element : String
@export var texture : Texture2D

Then you can make use something like @export var spells : Array[MyCustomSpellResource] in your player script or somewhere to have an array of spells and it will be editable in editor.

For your animating question, you might like more the interface of Sprite2D. It also supports animating spritesheets and the process is a bit simpler than AnimatedSprite2D. You just define how many rows and columns you have and then can animate frame property via code or AnimationPlayer.

1 Like

Not sure on the animated texture, I’ve also had little success with those.

It’s not showing a hit box shape because it’s not part of a collision shape in the scene. You would have to change your script to a @tool script for it to change the scene tree and potentially edit such parameters in-viewport. This might be difficult depending on the data you want to show and how it affects the generic spell scene. Personally I would try making the spells each their own scene or inherited scene.