godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Use a single frame of a sprite sheet on a Sprite node as a texture for another node #4521

Open coatlessali opened 2 years ago

coatlessali commented 2 years ago

Describe the project you are working on

A 2D platforming action game that is heavy on visual effects. When a player moves, I wish to emphasize this with an after image displaying the current frame of animation the player was in when the particle was created.

Describe the problem or limitation you are having in your project

I am trying to implement a simple trailing effect using the Particles2D node in which I want to copy the current frame of animation from a Sprite node (using a spritesheet as a texture) to be used in the trail. The end goal is to make something similar looking to the animation of Alucard's backdash from Castlevania: Symphony of the Night. Only the entire spritesheet can be inherited, meaning I would have to cut the sprite sheet, and then manage each of the individual frames and which frame needs to be copied when. 20220509_10h43m59s_grim

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

This feature would allow a single frame from a Sprite node to be inherited as the current texture. This could be used for things like a trailing effect on characters that shows a proper after-image of their current frame of animation. It could also be used to duplicate a sprite's current frame to be displayed on something like a screen in a game.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

An example of how this could be implemented is that we have a Root node, a KinematicBody2D with a Sprite, AnimationPlayer, and Particles2D.

To set the current texture to only an individual frame, it would look something like this: texture = get_node("/root/Node2D/KinematicBody2D/Sprite").frame_texture

Internally this could look something like:

  1. Get number of h_frames and v_frames for the sprite.
  2. Divide up the sprite sheet.
  3. Grab only the current region being displayed for the sprite.
  4. Make the region a texture.
  5. Copy the region as a texture for the Particles2D.

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

The only workaround I could find involves splitting up the sprite sheet individually and changing the texture manually depending on which frame is being displayed, or using an AnimatedSprite instead of a Sprite, which is also not ideal.

Is there a reason why this should be core and not an add-on in the asset library?

This isn't practical at all and results in extra files when all of the sprites could be stored in a sprite sheet, which makes it very user unfriendly for developers who work with sprite sheets primarily. Adding this would improve the experience for developers who want to use 2D FX involving duplication drastically.

KoBeWi commented 2 years ago

Or you could just duplicate the Sprite? With all the info it will display the same exact frame.