Is there a way to see what a clone is like? If I made two of the same sprite, how would I know which one was made second? ![]()
Yep! One common way is to keep a counter that increases every time you create a sprite.
For example:
let nextID = 0
function createEnemy() {
let enemy = sprites.create(...)
sprites.setDataNumber(enemy, "id", nextID)
nextID++
}
Now every sprite has its own unique ID:
- First sprite → ID 0
- Second sprite → ID 1
- Third sprite → ID 2
- etc.
Later, you can get a sprite’s ID with:
sprites.readDataNumber(enemy, "id")
If you’re using Blocks, there are Sprite Data blocks that let you set number data and read number data from a sprite, so you can do the same thing without switching to JavaScript.
You could also mention another option:
If you only need to know which sprite was created most recently, sprites.allOfKind(...) returns the sprites in creation order, so the last element is usually the newest. However, if sprites get destroyed, I wouldn’t rely on that. Giving each sprite its own ID with Sprite Data is the more reliable approach.
you can use the sprites data extension! (and/or a “enemies made” variable (I named it “ID” in my code))
I also included an example usage in there for you.
Try using sprite.id if you want to separate them
