How do I CLONE / DUPLICATE instance and its Properties?

  • Hi All,

    My project use Mouse (not touch), I have a button that creates Sprite object (1 instance per click) from Family: "Created_Objects", basically I can create many instances on the layout and tweak their size, rotation, Z-Depth, change animation frame, etc..

    Each Sprite Object have X amount of frames on their default animation on speed 0 (different variations).

    How do I do this:

    When holding "SHIFT" over a specific instance and Drag it aside, it will Clone/Duplicate the instance with it's CURRENT animation frame, Rotation, Size, Z-Depth or anything that tweaked to the one I cloned FROM.

    The result should be like this:

    I create as MANY INSTANCES as I want, I tweak each one to look totally different: changing frames, Rotation, Z-Depth, Size etc.. If I will hold "SHIFT" and drag ANY OF THE INSTANCES that I already created (not just the first or last created!) it will CLONE it with it's current properties (beside the position of course which I'm dragging aside).

    HELP?

    Any visual help, screenshot or project file will be very appreciate so I can explore and try it on my project. Thanks ahead! :)

  • Easy:

    You create a clone and continue to drag the original sprite.

  • Easy:

    You create a clone and continue to drag the original sprite.

    Thanks for the quick reply dop2000 :)

    I just tried this code but as I mention it's a Family "Created_Objects" and when I hold SHIFT and drag, it creates any of the Objects (different sprites) on the Family, I need it to only clone the instance.

    Any simple fix for that?

  • Cloning a family member (use "Create by name" action):

  • Thanks dop2000 it works like a charm!!

    Would you mind analyze it just so I can learn a bit about this all "JSON" thing... and the local string local variables you created temp and obj?

    I think that the JSON code is related to restore the data.. but I'm not sure and just guessing.

    You don't have to explain, I'm just curious because I have no clue what they does in this example and it'sa nice opportunity to learn it if you don't mind explain a noob.

  • dop2000 I just noticed when holding the SHIFT it will make the source (cloned from) instance jumping to the TOP Z-Order is it possible to do the same without changing it's current Z-Depth?

    It will be useful to make the CLONED created jump to the TOP Z-Depth.

  • AsJSON string contains all information about the object instance. You can use it to save/restore/copy instances easily. See the official manual:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/common-features/common-expressions

    .

    Source instance is the one you continue to drag. Its z-index doesn't change. You can change z-order of the newly created instance however you like.

  • AsJSON sounds like a VERY useful option, thanks for the info, I'll read about it and hopefully will understand how it works in different cases.

    I tried to make the created obj TOP-Z but I failed in different tests, whatever I do makes the source instance goes TOP as well, can you please help me out here?

  • The easiest solution is to use another family with the same set of objects:

  • Thank you so much dop2000 everything works EXACTLY as I imagined in my rusty brain!

    I'll play with this new feature to see if I didn't miss something or made a mistake while replicating the code, because in a first rough test it works great.

    oh, one more thing: YOU ROCKS! :)

  • Thanks to Dop2000's original code using SHIFT + DRAG aside to clone works.

    But I'm trying to limit it to only SHIFT + DRAG aside and nothing else.

    The thing is that it will also clone if I hold SHIFT + Middle or Left mouse button.

    So I tried to limit it with negative of these buttons in OR sub-event but still.. not getting the result.

    Any ideas how can I do that?

    My failed attempt:

    Thanks ahead for any help!

  • when you are using negatives, you don't use "OR", (because each condition cancels out the other one, so turn off the Make Or Block)

    then you want to move the local variables and events under that to be sub-events under where you check the mouse buttons...

  • Thanks for the quick reply AllanR I appreciate it!

    I tried to follow your instructions (hopefully I understood it):

    It works from my quick test, but since both Negative events are in the same block, how come it won't count as BOTH buttons hold together? I thought they should count as AND, means: Middle AND Right buttons together... this is why I get confused in the most basic C3 parts I guess.

    Again, it works from what I tested but I would like to understand if that's fine with you of course to explain it to a noob like myself.

    Thanks once again :)

  • It doesn't mean "buttons hold together". When there are multiple conditions in AND-event, each condition is evaluated separately, one by one from top to bottom. If every condition is true, the event will be executed.

    (Middle button not down)=true, (Right button not down)=true, the whole event will be (true AND true)=true.

    .

    In case of OR-event any condition needs to be true. If middle mouse button is not down (true), but right mouse button is down (false), the entire event will still be executed because (true OR false)=true

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the very detailed explanation dop2000 that explains many of my mistakes!

    more mistakes and questions to come... at least I'm learning a bit every day, which is great. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)