如何检测克隆的 x 和 y 位置?

How to detect the x and y position of a clone?

提问人:Zsergi 提问时间:9/29/2023 更新时间:9/30/2023 访问量:72

问:

我正在尝试制作一个标记,在每个克隆上放置一个数字,这样我就可以为每个克隆分配一个生命变量,但我无法这样做。有什么想法吗?

我尝试将每个克隆设置为不同的颜色,并使用它来将它们设置为一个数字,但我不知道如何获取克隆的位置,以便我可以用它移动标记。

mit-scratch (英语)

评论


答:

4赞 banana 9/30/2023 #1

一种方法是首先创建 1 个名为“克隆 ID”的变量(确保将其设置为 “for this sprite only”)并写下

enter image description here

[scratchblocks]
when green flag clicked
set [clone ID v] to [1]
[/scratchblocks]

[scratchblocks]
define create clone
create clone of [myself v]
change [clone ID v] by (1)
[/scratchblocks]

这可能并不明显,但是此代码使得您创建的每个克隆都具有唯一的克隆ID(这就是我们创建变量“仅用于此精灵”的原因),现在我们可以编写enter image description here

[scratchblocks]
when I start as a clone
forever
replace item (clone ID v) of [x positions] with ((x position))
replace item (clone ID v) of [y positions] with ((y position))
end
[/scratchblocks]

现在我们已经存储了每个克隆位置

如果您现在想为每个位置添加实时计数,您只需创建一个 Lives 变量和一个 Lives 列表,并将 X 位置替换为 Lives 变量,将列表替换为 Lives 列表enter image description here

[scratchblocks]
when I start as a clone
forever
replace (clone ID v) of [lives] with ((lives))
end
[/scratchblocks]