After-Image Matching Player Sprite

Godot Version

GODOT 4.3

Question

Hey there! I’m making this topic again, with some new parameters. Here is what I’m looking to do:
-when func after_image is triggered, create a child node that quickly fades away. The child node should match the Player’s current Sprite2D frame.

I think I’m really close to making what I want, but I need a few more things! Here is what I have so far:

func after_image():
	print("After Image Created")
	var current_texture = $Sprite2D.texture
	var after_image = Sprite2D.new()
	var frame_texture = ImageTexture.new()
	# Set the texture and frame of the after_image
	after_image.texture = current_texture
	after_image.frame = $Sprite2D.frame
	# Set global position and modulate alpha
	after_image.global_position = global_position
	after_image.modulate = Color(0, 255, 198, 1.0) 
	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()

Here is what it should be like: (greyish after-image whenever Zero is dashing)
mega-man-zero-game-boy-advance

Here is what the current code above is doing:

It is using the entire texture, instead of the “frame” for sure. But, what the heck else am I missing? Thanks!

Not sure how to fix your problem here, but in looking for something else I stumbled on this

Acceleration effect shader

It might be of some use for you.

I believe the last step is to copy the hframes and vframes to your new sprite2d!

func after_image():
	print("After Image Created")
	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.hframes = $Sprite2D.hframes ##!!##
	after_image.vframes = $Sprite2D.vframes ##!!##
	after_image.frame = $Sprite2D.frame

	# try this too, might help later
	after_image.show_behind_parent = true

	# Set global position and modulate alpha
	after_image.global_position = global_position
	after_image.modulate = Color8(0, 255, 198, 1.0) # Color8() takes 0-255 values, Color() takes 0.0 to 1.0
	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()

This will slice the texture just as your player is animated, you may need to set "show_behind_parent` as well! Great work from the last thread!

Thanks! I forgot to post, but I actually found the solution! If anyone is interested I can post the code when I get home.

1 Like

Please do

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.