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

#1 2009-06-28 05:40:16

Kaisa
Scratcher
Registered: 2009-06-28
Posts: 1

Event handlers.

On Scratch it is possible to write handlers for the following events:
- when GreenFlag clicked
- when <key> pressed
- when <sprite> clicked
- when I receive <message>
Is it possible to handle also events:
- when sprite dragged by user to new location
- when mouse button pressed, when released and to distinguish among left  and right buttons
?

Offline

 

#2 2009-06-28 07:35:25

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Event handlers.

when flag clicked, when [ ] key pressed, when [ ] clicked, and when I receive [ ]: There's already blocks for them...

when sprite dragged: first, make sure its draggable!
Make Variables: OldX, OldY
when sprite clicked
set [ OldX ] to ( x position )
set [ OldY ] to ( y position )
repeat until < not < mouse down > >
     if < not < ( x position ) = ( OldX ) > >
          broadcast [ dragged ]
          stop script
     if < not < ( y position ) = ( OldY ) > >
          broadcast [ dragged ]
          stop script


when mouse button pressed (distinguish)
copy to all sprites AND stage:
when sprite/stage clicked
if < mouse down >
     broadcast [ left mouse button down ]
else
     broadcast [ right mouse button ]

Offline

 

Board footer