How do I drag sprites during execution in Scratch?
6 Answers
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.)

- 1
- 1

- 32,893
- 9
- 77
- 89
-
Yes, though the offset calculations should be moved to before the loop, as there is no need to recalculate them each time. – boisvert Nov 20 '19 at 12:03
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.

- 3,679
- 2
- 27
- 53
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.
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]

- 2,342
- 5
- 25
- 34

- 53
- 6
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.

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

- 307
- 2
- 13