在 Scratch 中拖动精灵

发布于 2024-08-22 23:44:09 字数 29 浏览 6 评论 0原文

如何在 Scratch 中执行期间拖动精灵?

How do I drag sprites during execution in Scratch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

往昔成烟 2024-08-29 23:44:09

Scratch Wiki 对此进行了介绍。

boisvert的答案在技术上是正确的,但是,他的脚本总是将精灵从其中心拖动。使用稍微更高级的脚本将从拾取的位置拖动,更像是挂锁:(

when green flag clicked
forever
  if <<mouse down?> and <touching [mouse-pointer v]?>>
    repeat until <not <mouse down?>>
      set [offset x v] to ((x position) - (mouse x))
      set [offset y v] to ((y position) - (mouse y))
      go to x: ((mouse x) + (offset x)) y: ((mouse y) + (offset y))
    end
  else
    wait until <not <mouse down?>>
  end

上面的 wiki 链接具有这是视觉块格式。)

This is covered on the Scratch Wiki.

boisvert's answer is technically correct, however, his script will always drag the sprite from it's center. Using a slightly more advanced script will drag from the spot it was picked up, more like the padlock:

when green flag clicked
forever
  if <<mouse down?> and <touching [mouse-pointer v]?>>
    repeat until <not <mouse down?>>
      set [offset x v] to ((x position) - (mouse x))
      set [offset y v] to ((y position) - (mouse y))
      go to x: ((mouse x) + (offset x)) y: ((mouse y) + (offset y))
    end
  else
    wait until <not <mouse down?>>
  end

(The wiki link above has this is visual blocks format.)

虚拟世界 2024-08-29 23:44:09

单击精灵名称旁边的挂锁。它看起来会是开放的;然后精灵在可执行版本中变得可拖动。

或者,您可以使用脚本对其拖动行为进行编程:

if <mouse down>
  set x to (mouse x)
  set y to (mouse y)

它可以变得更聪明,在偏移位置跟随鼠标,有延迟,在放下时捕捉到某个位置,在鼠标经过它时突出显示某些内容...如果您使用脚本,您的选择是无限的。

Click the padlock next to the sprite name. It will look open; then the sprite becomes draggable in the executable version.

Alternatively, you could program its dragged behaviour with a script:

if <mouse down>
  set x to (mouse x)
  set y to (mouse y)

it can be made more clever, to follow the mouse at an offset position, with a delay, snap to a position when dropped, highlight something as it passes over it... If you use a script your choices are limitless.

月牙弯弯 2024-08-29 23:44:09

要获得快速简单的路线,您所要做的就是单击精灵的信息按钮: 单击此处查看图片1
之后,您应该找到显示“可以拖动播放器”的框,然后单击:点击此处查看图片 2
事实上就是这样。现在,每当有人玩你的游戏时,他们就可以拖动精灵。您只需让他们知道这是可能的,因为大多数项目不允许这样做。

For a quick and simple route, all you have to do is click the info button of the sprite: Click here for image 1.
After that you should find the box that says: can drag in player and click that: Click here for image 2.
This is actually it. Now whenever somebody plays your game they can drag the sprite. You just have to let them know that it is possible since most project don't allow it.

爱殇璃 2024-08-29 23:44:09

如果您不介意在脚本未运行时精灵是否仍可拖动,则可以在选择精灵时按右上角的 i 按钮。然后,按可以在播放器中拖动。但是,这不适用于 Scratch 3.0,因此您需要使用我的其他方法,即脚本。

when green flag clicked
forever
if <<mouse down?> and <touching [mouse-pointer]>>
go to [mouse-pointer]

If you would not mind if the sprite is still draggable when the script is not running then you press the i button at the top-right corner when the sprite is selected. Then, you press Can drag in player. However, this does not work for Scratch 3.0 and so you would need to use my other method, scripting.

when green flag clicked
forever
if <<mouse down?> and <touching [mouse-pointer]>>
go to [mouse-pointer]
删除会话 2024-08-29 23:44:09

您可以使用 布尔值、touching [mouse point]? 以及变量(mouse x) 和 < code>(mouse y) 获取鼠标坐标并检测鼠标是否按下。您可以这样做:

当绿色旗帜被点击时                                       sp; //当点击绿旗时,

永远                       nbsp;                     sp;                  < em>//永远这样做,

    如果触摸[鼠标指针]?并且按下鼠标?    //触摸鼠标指针?鼠标按下?

       将x设置为(鼠标x)            ;                         NBSP ;        //将我的 x 位置设置为鼠标的 x 位置。

       设置y为(鼠标y)            ;                         NBSP ;        //将我的 y 位置设置为鼠标的 y 位置。

    end if loop                                         sp;                  //如果以上所有内容不成立,则不要不使用鼠标

end forever loop                                             sp;        //永远重复这个过程!

如果您在其他方面需要更多帮助,可以关注我 >如果你想@endermite334。

You can use the <mouse down?> boolean, the touching [mouse pointer]? and the variables(mouse x) and (mouse y) to get the mouse's coordinates and to detect if the mouse is down. Here is how you can do it:

when green flag clicked                                               //when the green flag is clicked,

forever                                                                         //do this forever,

    if touching [mouse pointer]? AND mouse down?    //touching the mouse pointer? The mouse down?

        set x to (mouse x)                                               //set my x position to the mouse's x position.

        set y to (mouse y)                                               //set my y position to the mouse's y position.

    end if loop                                                              //if everything above is not true, don't go to mouse

end forever loop                                                        //repeat this process forever!

If you need more help with other things, you ca follow me if you want to @endermite334.

硬不硬你别怂 2024-08-29 23:44:09

在 Scratch 3.0 中,精灵默认是可拖动的。您可以使用设置拖动模式[不可拖动]来更改它

Sprites are by default draggable in Scratch 3.0. You can change that by using set drag mode [not draggable]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文