Godot Version
GODOT 4.3
Question
Wasn’t sure weather to put this in animation or shaders. Anyways:
Edit: I left out very important information here! I want an after image that reflects the player’s current sprite, at that frame.
Something like:
-When speed is over a certain amount
–Create child node (after image)
After image would not be animated, but be a snapshot of the player’s frame the moment it was created.
Here’s a gif that more accurately represents what I’d like! Notice Zero has a greyish after image that reflects his current sprite, then it fades quickly. Not just for dashing either, but for any time he’s at a certain speed.
This came close but something is missing!
func after_image():
var current_texture = $Sprite2D.texture
var after_image = Sprite2D.new()
# Set the texture and frame of the after_image
after_image.texture = current_texture
after_image.frame = $Sprite2D.frame
# Calculate the frame size and coordinates
var frame_size = current_texture.get_size() / Vector2($Sprite2D.hframes, $Sprite2D.vframes)
var frame_coords = Vector2($Sprite2D.frame % $Sprite2D.hframes, $Sprite2D.frame / $Sprite2D.hframes) * frame_size
# Enable region and set the region rectangle
after_image.region_enabled = true
after_image.region_rect = Rect2(frame_coords, frame_size)
# Set global position and modulate alpha
after_image.global_position = $Sprite2D.global_position
after_image.modulate.a = 0.5
# Add after_image as a child
add_child(after_image)
# Wait before removing the after_image
await get_tree().create_timer(0.2).timeout
after_image.queue_free()