All Questions

Community

t
duong tuan

[VFX] Ghost Trail for sprite have multibody.

Thanks for this lesson.

Based on what I learned in this lesson, I tried this effect out on a character with multiple child sprite.

It works quite well, I hope this code can help someone refer.

https://i.ibb.co/K7dN07n/Screen-Shot-2020-10-24-at-5-14-38-PM.png

https://media.giphy.com/media/TtCHP8D601877eORiW/giphy.gif

const GhostEffect: PackedScene = preload("res://src/effects/GhostEffect.tscn")

func spawn_ghost_effect(sprite: Sprite):
	var ghost := GhostEffect.instance()
	ghost.texture = sprite.texture
	ghost.transform = sprite.transform
	ghost.hframes = sprite.hframes
	ghost.frame = sprite.frame
	ghost.offset = sprite.offset
	ghost.flip_h = sprite.flip_h
	ghost.flip_v = sprite.flip_v
	ghost.global_position = sprite.global_position

	var main = get_tree().current_scene
	call_deferred("add_child", ghost)


func spawn_ghost_effect_all(sprite: Sprite):
	spawn_ghost_effect(sprite)
	for child in sprite.get_children():
		if child is Sprite:
			spawn_ghost_effect_all(child)

  • Nathan Lovato replied

    Thanks for sharing! Note that for performance, it may be best to use viewports instead, to render the animated character to a viewport and buffer the rendered textures over several frames.

  • t
    duong tuan replied

    Thank Nathan.

    I had an idea at first that I would use viewport, but I didn't know how to do it. Can you add it in the future? I have high hopes for it. :)