Discuss Scratch

tb259
New to Scratch
10 posts

Cloning vs duplicating?

Hey there,

I'm still pretty new to scratch (and programming in general), so I was wondering if it is “better” to clone sprites instead of duplicating. I want to use an enemy sprite multiple times (respawning after a certain time or after the other sprite was killed).

With duplicating it's pretty straight forward, just duplicate it and spawn it with a broadcast later.
With cloning I had some problems with broadcasts affecting every clone within the sprite and stuff, so I had to attach IDs to the clones which resulted in longer “codes”. That's when I was asking myself: why even bother? Is there a benefit of cloning (at least in this case, as I could imagine there are benefits)?

Another example is a gameover-screen with multiple costums at the same time. I did it 1. with cloning and changing the costume and 2. with different sprites for each costume. I'm just wondering if one or the other is more efficient.

Best regards

PS. I'm not sure if I should've asked this topic in “Questions about Scratch”.
deck26
Scratcher
1000+ posts

Cloning vs duplicating?

It depends!

If the objects are behaving identically (or any differences are minor) you presumably will have to duplicate any changes you make across multiple sprites which can lead to errors. But if clones created at different times behave differently anyway and there are relatively few perhaps different sprites is easier.

Creating clones does add to the work Scratch has to do so it can make sense to hide and reuse clones rather than delete and recreate but in most cases that is not really an issue.
The_Imaginarium
Scratcher
1000+ posts

Cloning vs duplicating?

There are big differences.

When duplicating, clones and other sprites can detect location and attributes of that specific duplicate fairly easy. With clones, you cannot accurately reckon if you are touching a clone or not. The closest way to do that would be to store the clone's attributes in a list and use the Pythagorean theorem to find the distance to the clone.
I'm currently working on a project which requires me to get a lot of information about a lot of clones, which is very tedious and slows down the project significantly.

So that's +1 for duplicates

However, in a project which you're using many, many duplicates it can get very messy, because it is difficult to test and easily make changes to all of the duplicates without deleting and re-duplicating over and over again. And the amount of broadcasts can very high and be annoying to keep track of.

So that's +1 for clones

So it's hard to say. In my opinion, I'd just go with what is easiest and fits your situation.
tb259
New to Scratch
10 posts

Cloning vs duplicating?

Thanks for your fast and detailed answers, really helped me a lot.
orangetheory
Scratcher
500+ posts

Cloning vs duplicating?

Cloning is best when you want the clones to do similar things, and if you want them to do different things, that is more advanced but at the moment you do not need to know that. Soon you will, tho, if you get better. Cloning also looks cleaner, and is better for hosting many scripts at the same time, while only using one script. I personally choose cloning over duplicating. But sometimes usually over 50-100 clones on slow computers creates lag in the editor and project, and may crash some things, but I'm assuming you have an OK computer, so you could probably host 100-200 clones without lagging. Good computers can hold all 300, depends on their core and processor. Anyways, that's an advanced topic.

Duplicating isn't that good in my opinion because you can only host up to the amount of times you duplicated the sprite on the screen. For example, if you duplicate something 5 times you can only use it 5 times on the screen, whereas cloning could host up to 300 clones at the same time. But duplicating is best if you want to make different things to different actions, even though you could still do that with cloning, duplicating is easier for this task. Although too much sprites could create lag in both the editor and the project, like clones, but duplicates can create lag much faster than clones because, for example, you have 50 clones, then it starts lagging, but then you have only 12 sprites and it starts lagging, usually. Duplicating also looks messier and it makes you having to put different code in all of them, much more time consuming depending on what you want to make.

Hope you understood cloning vs. duplicating, and I hope this helped

-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums
tb259
New to Scratch
10 posts

Cloning vs duplicating?

Another different perspective, thanks for your input - very helpful indeed!

I'll stick with duplicating for my first small project, since there won't be many sprites anyways, but I'll definitely lock forward to learn more about clones later.
helloworldbyeworld
Scratcher
1000+ posts

Cloning vs duplicating?

If you are okay with the coding (if what you want to do is not too complicated, there isn't really much coding to do) and you don't need to detect lots of different attributes, then I'll suggest cloning. It basically creates a copy of the sprite and always follows the same script, namely the script under the ‘when I start as a clone’ event hat block. All clones follow the script, so if you want to assign different scripts to different clones, duplicating the sprite would be better (you could assign clone IDs, but I feel like this is very cumbersome).

With duplicating, you could pretty much do anything you want as a sprite. However, if you have too many sprites, debugging can be hard and things will look messy. You can add lots of different scripts to different sprites, and you can also detect lots of the sprite's attributes.

So like lots of people said, it really depends on how you want to use it.

Helloworldbyeworld | 1200+ posts
Have a great day

Powered by DjangoBB