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)
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!
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!