Sorry, was busy yesterday and did not have time to reply.
For one, I would not recommend placing this in the _process
function. Instead, call it only when you need it by placing it in its own function. Something like this:
func copy_sprite():
var sprite_ref = $AnimatedSprite
var sprite_clone = sprite_ref.duplicate()
sprite_clone.name = "AnimatedSpriteClone"
add_child(sprite_clone)
# so its visible
# (otherwise it will be at the exact same position as the original AnimatedSprite)
sprite_clone.global_position += Vector2(64, 64)
Then you can trigger it only when you need it by calling copy_sprite()
. For testing, you could try something like this:
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):
copy_sprite()
@"K-Storm-Studio Ltd" said:
it does works partially, it creates a cloned sprite but it is not animated and it is not the same at the original sprite
Can you explain what you mean? I'm a little confused as to what is happening. If it is not showing the same animation, it may be that you need to tell the new AnimatedSprite to use the same animation as the duplicated AnimatedSprite. Something like this (in the copy_sprite
function):
sprite_clone.play($AnimatedSprite.animation)