如何创建一个功能性的拖放系统

huangapple go评论45阅读模式
英文:

How do I make a functional drag-and-drop system

问题

背景信息

正如我之前所述在这里,我正在尝试在Scratch中创建一个植物大战僵尸的修改版。 我的主要问题仍然是尝试创建拖放系统(点击种子包然后拖放它),但问题似乎仍然相同,例如在编辑器中,我只能拖动种子包,在预览模式中,我什么都无法拖动。

我尝试过的事情(scratchblocks格式)

当我点击种子包时

[scratchblocks]
当此角色被点击
大于或等于([豌豆射手成本 v])(100)
[/scratchblocks]

为了定义“大于或等于(变量)(数字)”

[scratchblocks]
定义 大于或等于(变量)(数字)
如果 <<(变量) > (数字)>> 或 <<(变量) = (数字)>> 则
广播 [消息1 v]
否则
结束
[/scratchblocks]

种子包发送消息给特定植物的代码

[scratchblocks]
当我接收到 [消息1 v]
创建克隆自 [自己 v]
[/scratchblocks]

拖放克隆的代码

[scratchblocks]
当我作为克隆体启动时
如果 <<鼠标按下?>> = [false]>> 则
一直
显示
将 [亮度 v] 效果设置为 (40)
移动到 x: (鼠标x) y: (鼠标y)
结束
否则
删除此克隆
结束
[/scratchblocks]

请注意,与上次不同的是,我实际上已经初始化了豌豆射手的成本。

如何创建一个功能性的拖放系统

我的问题

我做错了什么,导致代码仍然像这样?

英文:

Background information


Like I have stated before here, I am trying to create a Plants vs. Zombies mod in Scratch. My main concern still seems to be attempting to create the drag-and-drop system (clicking the seed packet and then dragging and dropping it), however, the problem still seems to be the same, for example, in the editor, I can only drag the seed packet, and in preview mode, I can't drag anything.



What I have tried (scratchblocks format)



When I have clicked the seed packet

[scratchblocks]
when this sprite clicked
Greater than or equal to ([peashooter cost v]) (100)
[/scratchblocks]

To define Greater than or equal to (var) (number)

[scratchblocks]
define Greater than or equal to (var) (number)
if &lt;&lt;[(var)] &gt; [(number)]&gt; or &lt;[(var)] = [(number)] then
broadcast [message 1 v]
else
end
[/scratchblocks]

The code for when the seed packet sends the message to the specific plant

[scratchblocks]
when I receive [message 1 v]
create clone of [myself v]
[/scratchblocks]

The code for dragging and dropping the clone

[scratchblocks]
when I start as a clone
if &lt;&lt;mouse down?&gt;&gt; = [false]&gt; then
forever
show
set [brightness v] effect to (40)
go to x: (mouse x) y: (mouse y)
end
else
delete this clone
end
[/scratchblocks]

Note that unlike last time, I have, in fact, initialized the cost for the Peashooter:

如何创建一个功能性的拖放系统



My question



What am I doing wrong that would still cause the code to be like this?

答案1

得分: 1

当编辑时,Scratch允许您拖动任何内容。要让精灵随时可拖动,请转到设置部分(浅蓝色)并添加“将拖动模式设置为可拖动”,然后将其添加到您希望可拖动的精灵的“当旗帜被点击”中。这将允许您随时拖动精灵。以下是我创建拖动系统的方式:设置拖动模式为可拖动,然后使用循环测试鼠标是否按下,如果鼠标没有按下,它将重新定位种子包到其应该的位置。这样,它就可以被拖动,但当玩家释放它时,它会重置位置。

英文:

When editing, scratch allows you to drag anything. To allow a sprite to be draggable whenever, go to the seneing section (light blue) and add the "set drag mode to draggable" and add it to "when flag clicked" in the sorite you want to be draggable. This will allow you to drag the sprite whenever you want. Here is how I would create a drag system, set drag mode to draggable, then, have a loop test if mouse is down, if mouse is not down it will reposition the seed packet to where it is supposed to be. That way, it is draggable, but when the player releases it it resets position.

huangapple
  • 本文由 发表于 2023年5月26日 00:10:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76334325.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定