Cloning a node/sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jbibbo

I want to make sure I am not missing anything. It doesn’t look like there is the ability to clone( or instance) an individual node, only the ability to instance an entire scene. Is this correct?

I have a pool of symbols(sprites) where some are animated, and some are static. The game pulls from the pool and puts the symbols on reels at various places. Initially, I was just taking the textures from the symbol pool’s symbols(sprite) and attaching them to the reels at the various places. This was fine for static sprites. But realized this didn’t work for the animated sprites. I started to look around a way to clone the sprite from the symbol pool and only found the documentation on instancing a scene.

Maybe scenes are lightweight enough that it is not too bad to break out a single symbol per scene, it just seems like it would be a common request to clone a single object in the game object tree so I didn’t need to do this.

:bust_in_silhouette: Reply From: kidscancode

A scene is nothing but a collection of nodes, and that collection could have just one item.

Depending on your application, if you have an existing node in the tree that you want a copy of, you can use duplicate(), which includes flags for instancing:

duplicate() doesn’t seem to be recursive. Does that sound right? I tried to duplicate a node that had children but only the node seemed to get cloned. Passed in no parameters, so should be using flag = 15 , or all flags set.

jbibbo | 2018-05-24 16:57