3

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

4

6 回答 6

8

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 链接是可视块格式。)

于 2014-11-20T15:05:57.960 回答
5

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

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

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

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

于 2012-07-11T23:08:11.407 回答
0

您可以使用<mouse down?>boolean、the和touching [mouse pointer]?变量来获取鼠标的坐标并检测鼠标是否按下。您可以这样做:(mouse x)(mouse y)

当绿旗被点击                                               时//当绿旗被点击时,
永远                                                                         //永远这样做,
    如果触摸[鼠标指针]?并按下鼠标?    //触摸鼠标指针?鼠标掉了?
        set x to (mouse x)                                                //将我的 x 位置设置为鼠标的 x 位置。
        set y to (mouse y)                                                //将我的 y 位置设置为鼠标的 y 位置。
    end if loop                                                               //如果上面的都不是真的,不要去鼠标
永远结束循环                                                        //永远重复这个过程!

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

于 2019-11-04T13:45:48.723 回答
0

在 Scratch 3.0 中,精灵默认是可拖动的。您可以通过使用更改它set drag mode [not draggable]

于 2020-08-14T00:25:11.547 回答
0

如果您不介意在脚本未运行时精灵是否仍可拖动,则在i选择精灵时按下右上角的按钮。然后,您按Can drag in player。但是,这不适用于 Scratch 3.0,因此您需要使用我的另一种方法,脚本。

when green flag clicked
forever
if <<mouse down?> and <touching [mouse-pointer]>>
go to [mouse-pointer]
于 2019-10-12T07:44:19.010 回答
0

要获得快速简单的路线,您只需单击精灵的信息按钮:单击此处查看图像 1。之后,您应该找到显示:并单击
该框:单击此处查看图像 2。 这实际上是它。现在,每当有人玩您的游戏时,他们都可以拖动精灵。您只需要让他们知道这是可能的,因为大多数项目都不允许这样做。can drag in player

于 2017-01-05T04:07:11.943 回答