Discuss Scratch

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

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
mitchboy
Scratcher
1000+ posts

how do I make it so the user can click and drag

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
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

mitchboy wrote:

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
That way makes the sprite able to be dragged the whole time, the script helps time when you can drag sprites.
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.

See here.
scubajerry
Scratcher
1000+ posts

how do I make it so the user can click and drag

drmcw wrote:

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.

See here.
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.
drmcw
Scratcher
1000+ posts

how do I make it so the user can click and drag

scubajerry wrote:

drmcw wrote:

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.

See here.
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.

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

hi
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

scrachchamp20 wrote:

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

mitchboy wrote:

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
WHAT

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
What is the green block?
BF10
Scratcher
500+ posts

how do I make it so the user can click and drag

Bat_Boy wrote:

mitchboy wrote:

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
WHAT

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
What is the green block?

Please do not bump.

They are Operators.
75hi5s
Scratcher
100+ posts

how do I make it so the user can click and drag

PhirripSyrrip wrote:

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?>>
I tried, it doe not work
75hi5s
Scratcher
100+ posts

how do I make it so the user can click and drag

mitchboy wrote:

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
Where is the “I” button?
lil_David
Scratcher
55 posts

how do I make it so the user can click and drag

75hi5s wrote:

mitchboy wrote:

Photoguy77 wrote:

forever 
if <<mouse down> and <touching [mouse pointer v]>
go to [mouse pointer v]
You should be able to drag this sprite now!
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?”
Where is the “I” button?

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.

Powered by DjangoBB