godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add a way to specify per-animation offsets to AnimatedSprite #665

Open iway1 opened 4 years ago

iway1 commented 4 years ago

Describe the project you are working on: Top down RTS game.

Describe the problem or limitation you are having in your project: Characters use an AnimatedSprite node to change between their respective animations. The animations have different center points by their pixel value.

Changing the offset always affects every animation, so it is impossible for both animations to be centered correctly when contained within the same AnimatedSprite. This results in at least one animation being offcenter.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

Allow offsets to be specified per animation, giving a different offset to each animation in question.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Allow multiple offsets to be specified in the editor.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

It can be worked around by using the frame_changed() signal. It requires hardcoding the offsets per animation which isn't a desirable solution. It will cause additional code to be ran every single frame to check whether the animation has changed. If there were some "animation_changed()" signal that would be much more efficient and match the problem better.

Is there a reason why this should be core and not an add-on in the asset library?: Not a big enough feature to warrant an add on. It would be very useful to anyone using an AnimatedSprite with multiple animations where the offsets are different for different animations.

EDIT:

The workaround actually does not work. Since frame_changed is called AFTER the frame has changed, the first frame will be played with the previous animations offsets. So the sprite "jumps" for a frame as the second frame is played with the correct offsets.

EDIT 2:

New workaround by overriding the "play" function. Works like it should. Still requires me to hardcode offsets which is less than ideal.

Calinou commented 4 years ago

Related to #94.

elvisish commented 9 months ago

I'd suggest this would be extremely useful for death animations, where the character will generally need more horizontal space for falling back compared running, jumping and idle animations. While it can be done with AnimationPlayer, it would make a lot more sense to allow specific animations have their own offsets in AnimatedSprite (this could be added on in addition to the global offset in the AnimatedSprite node).