This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-10-24 20:02:26

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

How to detect dragging??

If you let a sprite be able to get dragged around on the site in presentation mode, how can you detect when it is being dragged??


Hai.

Offline

 

#2 2009-10-24 20:24:25

greenflash
Scratcher
Registered: 2009-05-27
Posts: 1000+

Re: How to detect dragging??

[blocks]
<when green flag clicked>
<forever>
<if><< <touching[ mouse pointer] <and><mouse down?>  >>
<set{ drag }to( 1
<else>
<set{ drag }to( 0
<end>
<end>
[/blocks]

Try that script, it should work.


http://i48.tinypic.com/2wrkirk.pnghttp://i46.tinypic.com/6r5zk7.pnghttp://i45.tinypic.com/2vtxr1t.png

Offline

 

#3 2009-10-24 21:22:15

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How to detect dragging??

Oh yeah. Why didn't I think of it?  tongue


Hai.

Offline

 

#4 2009-10-24 22:05:50

greenflash
Scratcher
Registered: 2009-05-27
Posts: 1000+

Re: How to detect dragging??

Glad to help!  big_smile


http://i48.tinypic.com/2wrkirk.pnghttp://i46.tinypic.com/6r5zk7.pnghttp://i45.tinypic.com/2vtxr1t.png

Offline

 

#5 2009-10-25 00:13:46

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How to detect dragging??

Thanks!


Hai.

Offline

 

#6 2009-10-25 11:10:56

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: How to detect dragging??

greenflash wrote:

[blocks]
<when green flag clicked>
<forever>
<if><< <touching[ mouse pointer] <and><mouse down?>  >>
<set{ drag }to( 1
<else>
<set{ drag }to( 0
<end>
<end>
[/blocks]

Try that script, it should work.

I'd have to say, that was pretty smart, but thats when the sprite is clicked or hold-clicked on.
[blocks]
<when green flag clicked>
<forever>
<set{ x }to( <x position>
<set{ y }to( <y position>
<if><< <touching[ mouse pointer]  <and> <mouse down?> >>
<wait until> <<  <not> <mouse down?> >>
<if> << <<  <not> <( <x position> <=> <{ x }> )> >> <or> <<  <not> <( <y position> <=> <{ y }> )> >> >>
<set{ drag }to( 1
<else>
<set{ drag  }to( 0
<end>
<end>
<end>
[/blocks]
Phew! I hope that helps!
EDIT: Since you may not understand the jumble of scripts, I'll put it into code for you.

Code:

forever:
set x to x position
set y to y position
if mouse down and touching mouse pointer:
     wait until not mouse down
     if not x = x position or y = y position:
          set drag to 1
     else:
          set drag to 0

Last edited by Greatdane (2009-10-25 11:15:29)


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#7 2009-10-25 12:12:16

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How to detect dragging??

Greatdane wrote:

greenflash wrote:

[blocks]
<when green flag clicked>
<forever>
<if><< <touching[ mouse pointer] <and><mouse down?>  >>
<set{ drag }to( 1
<else>
<set{ drag }to( 0
<end>
<end>
[/blocks]

Try that script, it should work.

I'd have to say, that was pretty smart, but thats when the sprite is clicked or hold-clicked on.
[blocks]
<when green flag clicked>
<forever>
<set{ x }to( <x position>
<set{ y }to( <y position>
<if><< <touching[ mouse pointer]  <and> <mouse down?> >>
<wait until> <<  <not> <mouse down?> >>
<if> << <<  <not> <( <x position> <=> <{ x }> )> >> <or> <<  <not> <( <y position> <=> <{ y }> )> >> >>
<set{ drag }to( 1
<else>
<set{ drag  }to( 0
<end>
<end>
<end>
[/blocks]
Phew! I hope that helps!
EDIT: Since you may not understand the jumble of scripts, I'll put it into code for you.

Code:

forever:
set x to x position
set y to y position
if mouse down and touching mouse pointer:
     wait until not mouse down
     if not x = x position or y = y position:
          set drag to 1
     else:
          set drag to 0

Hmmm, yes. I tried greenflash's code and it only seem to detect whether it is clicked or not.


Hai.

Offline

 

#8 2009-10-25 14:28:25

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: How to detect dragging??

Oh, well. Hope that helps!  smile


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#9 2009-10-25 17:18:04

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How to detect dragging??

Thanks!!
edit:Yes, it helps.  But it only detects after the sprite has been dragged, how to detect the second it is dragged?

Last edited by fg123 (2009-10-25 17:41:06)


Hai.

Offline

 

#10 2009-10-25 18:20:18

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: How to detect dragging??

That's simple. Just replace the 'wait until not mouse down' with 'wait 0.1 secs'.

That should work.

(It's a tenth of a second it's dragged.)


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#11 2009-10-25 22:31:25

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How to detect dragging??

It kinda works, but it's very glitchy...and sometimes there is a layer problem


Hai.

Offline

 

Board footer