Logo
  • Features
  • Educators
  • What's New
  • Blog
  • Showcase
  • About us
  • Contact
Try it now!
How to Create a Clone with Preset Property?
🐑

How to Create a Clone with Preset Property?

Cloning is not easy to use in Scratch

In Scratch games, we often use clones, especially in games that require a lot of enemy characters. Using clones can help us avoid creating many duplicate sprites. However, cloning is not very easy to use, especially when you need to distinguish between multiple clones of the same sprite. Some experienced Scratchers will use variables that only apply to the current sprite to solve the problem of identifying clones. For example, using variables that only apply to the current character to give clones an ID. This process is often more complex and less intuitive.

In Gandi IDE, we have developed the Dolly extension to solve various problems when using clones.

In the Showcase game Dizziness, out-of-control robots randomly appear from the left and right sides of the stage, approach and attack the player. This is where we use the blocks in Dolly to generate clones of the out-of-control robot.

This is the project file for this best practice. Let's take a look at how it's done.

Best Practice - How to Create a Clone with Preset Property? by @Jamin /Scratch project hosted on Cocrea.

This is where we use the blocks in Dolly to generate clones of the out-of-control robot. Hosted on Cocrea.world, powered by Gandi IDE.

cocrea.world

Best Practice - How to Create a Clone with Preset Property? by @Jamin /Scratch project hosted on Cocrea.

Prerequisites

You need to have a basic understanding of cloning in Scratch. You can refer to this official Scratch Wiki to learn more.

Cloning - Scratch Wiki

en.scratch-wiki.info

Cloning - Scratch Wiki

Before using Dolly, you need to install the Dolly extension in the extension library of Gandi IDE.

For detailed instructions on how to use Dolly, please refer to this document.

Dolly Extension, Clone Utils for Scratch - Gandi IDE

Dolly is a Scratch extension that helps you manage clones in the stage. Create clones attached with key-value data, find any clones by a k-v pair or an id, detect "is touching" with a specific clone, etc. Dolly makes Scratch more objective-oriented programming.

getgandi.com

Dolly Extension, Clone Utils for Scratch - Gandi IDE

Step-by-step Guide

Step 1: Pre-setting for sprite

The costume of the enemy character is shown in the figure. It also has a series of frame animation costumes.

image

In the game, two types of clones need to be generated, one facing right and the other facing left. Therefore, the rotation style of the sprite is set to left-right flip to facilitate the generation of clones with the correct appearance.

Step 2: Generate clones with preset direction property

Use this block in the Dolly extension to generate clones.

image

In the block, you can preset a property for the clone. After the clone is generated, you can use another block to get this property.

For example, we preset the direction property for the clone. Fill in "direction" in the key field and "left" in the value field to indicate that this clone is a clone facing left.

image

Similarly, if you want to generate clones facing right, you can fill in "right" in the value field.

image

Step 3: Set the position and direction of clones according to property

You can use this block in Dolly to get the property of the clone.

image

When the clone is generated, according to its direction property, let it face the right direction, move to the appropriate position. The clone facing right needs to be moved to the far left, and conversely, the clone facing left needs to be moved to the far right. Then, the clone needs to move forward and change its costume to play the frame animation.

image

Step 4: Conditions for the appearance of clones

After the program starts running, enemies appear randomly. The longer the game time, the more frequent the appearance of enemies. We can use random numbers and timer to make it. The script is like this.

image

In this way, we can generate clones moving in different directions.

Note

Cancel the limit on the number of clones

In Scratch, the max number of clones is 300. In Gandi IDE, you can use this block in the Fermi extension to set the max number of clones.

image

However, it should be noted that too many clones may cause the program to use too many resources and cause lag, so use it with caution.

In addition, you can also use this block in Fermi to cancel the fence of the stage area, so that clones can move outside the stage area.

image

For detailed instructions on how to use the Fermi extension, please refer to the documentation.

Fermi Extension, unchain the limitations of Scratch - Gandi IDE

Fermi helps you unchain the limitations of Scratch. With the Gandi Fermi, you can create unlimited clones, increase refresh rate to 120 fps, and move the sprite to any position you want, even off the stage.

getgandi.com

Fermi Extension, unchain the limitations of Scratch - Gandi IDE
💡
If you have any questions or suggestions, you can find us in the discord channel: https://discord.gg/U3nyveCvRa
Logo

Designed by 2ndR with love

Discord