Hey @mlgcoolguys_1, welcome to the forum!
The interaction you’re looking for here is the object.clone()
method.
If you have a character/object on screen, you can name it, then us the clone method like this to get a copy.
// Cloning
var myClone = object.clone();
You can move that clone around, or give it more information to use, by saying cloneName.property
, like this:
// Move the clone to 50, 100
myClone.x = 50;
myClone.y = 100;
// Give the clone a "speed" value to use later.
myClone.speed = 5;
I’m attaching an example that shows you how to then allow objects to interact with clones. The easiest way is by using hitTest
on a clone and another object. You can do this, by looking through all of the clones of an object like this:
// Go through all clones and see if they hit me.
for (var c of myClone.clones) {
if (this.hitTest(c)) {
this.remove(); // Delete this object
return; // Stop checking.
}
}
In the example, I delete rain drops, and allow other types of clones to play an animation, but you can really do anything! (I need to add this example to the website, it’s super handy!)
We’re happy to help, just reach out if you need any more assistance!
CloningDemo.wick (58.1 KB)