Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how do I make it so the user can click and drag
- meowmoo
-
Scratcher
500+ posts
how do I make it so the user can click and drag
I got an awesome idea for making a tower defense game on scratch but I need to make it so the player can click and drag towers
- Photoguy77
-
Scratcher
100+ posts
how do I make it so the user can click and drag
foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]


- mitchboy
-
Scratcher
1000+ posts
how do I make it so the user can click and drag
You don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
- scubajerry
-
Scratcher
1000+ posts
how do I make it so the user can click and drag
On the sprite, click the circled I (I think) Then click allow drag in player.
- Eintity
-
Scratcher
100+ posts
how do I make it so the user can click and drag
That way makes the sprite able to be dragged the whole time, the script helps time when you can drag sprites.You don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
- scubajerry
-
Scratcher
1000+ posts
how do I make it so the user can click and drag
Be aware that although the allow drag in player check box is nice and easy you do get a difference in functionality between the editor and the player which can lead to some nasty bugs.There may be differences, but I think your example is flawed. It meows for me in all modes. I suspect that you haven't started the program in the editor mode my clicking the GF.
See here.
- drmcw
-
Scratcher
1000+ posts
how do I make it so the user can click and drag
Be aware that although the allow drag in player check box is nice and easy you do get a difference in functionality between the editor and the player which can lead to some nasty bugs.There may be differences, but I think your example is flawed. It meows for me in all modes. I suspect that you haven't started the program in the editor mode my clicking the GF.
See here.
You didn't read the instructions. If you drag in the player then you get a meow when the sprites touch, you only get a meow in the editor when it is dropped and they touch.
- clubpenguin552222
-
Scratcher
100+ posts
how do I make it so the user can click and drag
When this sprite clicked
repeat until <mouse down>
go to [mouse pointer v]
Last edited by clubpenguin552222 (Sept. 14, 2013 15:30:19)
- PhirripSyrrip
-
Scratcher
500+ posts
how do I make it so the user can click and drag
I prefer this script, you don't need to check any box, dragging is smooth, the sprite doesn't go out of the project box like it can do when you can drag in player and you can control if you want a sprite to be draggable in only certain points of a project:
when gf clicked
forever
if <mouse down?> then
if <touching [mouse-pointer v]?> then
set [X-Offset v] to ((mouse x)-(x position))
set [Y-Offset v] to ((mouse y)-(y position))
repeat until <not<mouse down?>>
set x to ((mouse x)-(X-Offset))
set y to ((mouse y)-(Y-Offset))
end
else
wait until <not<mouse down?>>
Last edited by PhirripSyrrip (Sept. 14, 2013 16:27:03)
- scrachchamp20
-
Scratcher
11 posts
how do I make it so the user can click and drag
how do I make it so the user can click and drag an item to something and if it is not touching the something the item goes back to where it started?
- krausem2181
-
Scratcher
1 post
how do I make it so the user can click and drag
[
when green flag clicked
move (10) steps
- deck26
-
Scratcher
1000+ posts
how do I make it so the user can click and drag
how do I make it so the user can click and drag an item to something and if it is not touching the something the item goes back to where it started?You should start your own topic.
The answer to your question is to store the x,y coordinates when you pick up the item and return it there if it isn't touching when you let go.
- Bat_Boy
-
Scratcher
1 post
how do I make it so the user can click and drag
WHATYou don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
What is the green block?foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
- BF10
-
Scratcher
500+ posts
how do I make it so the user can click and drag
WHATYou don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]What is the green block?foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
Please do not bump.
They are Operators.
- 75hi5s
-
Scratcher
100+ posts
how do I make it so the user can click and drag
I prefer this script, you don't need to check any box, dragging is smooth, the sprite doesn't go out of the project box like it can do when you can drag in player and you can control if you want a sprite to be draggable in only certain points of a project:I tried, it doe not workwhen gf clicked
forever
if <mouse down?> then
if <touching [mouse-pointer v]?> then
set [X-Offset v] to ((mouse x)-(x position))
set [Y-Offset v] to ((mouse y)-(y position))
repeat until <not<mouse down?>>
set x to ((mouse x)-(X-Offset))
set y to ((mouse y)-(Y-Offset))
end
else
wait until <not<mouse down?>>
- 75hi5s
-
Scratcher
100+ posts
how do I make it so the user can click and drag
Where is the “I” button?You don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
- lil_David
-
Scratcher
55 posts
how do I make it so the user can click and drag
Where is the “I” button?You don't need to do that. All you have to do is click on the “I” in the sprite pane and select “Draggable in player?”foreverYou should be able to drag this sprite now!
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]

The lowercase I on the top left.
Last edited by lil_David (Nov. 14, 2015 03:03:31)
- Photoguy77
-
Scratcher
100+ posts
how do I make it so the user can click and drag
So… a little explaining behind my method:
- Yes, the way I demonstrated is equivalent to the “draggable in player.” But…
- Replace the for loop with a while gameIsGoing == true and it only drags in game.
- Discussion Forums
- » Help with Scripts
-
» how do I make it so the user can click and drag

