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

#1 2013-04-05 06:13:30

Roxiy
New Scratcher
Registered: 2013-03-31
Posts: 4

Object/Sprite hovering over Object

Hi,

is it possible, to activate a script when an object is hovering over another object? We want to play a sound when an object is moved by the player over another object, but this only works when you click on it.

This is what we have:

when object1 clicked
forever
  forever if touching object2? 
    play sound1 until done
You can drag the Object1 with your mouse, but the sound only plays when you let go while its over object2 and click on object2. We want the sound to play while object1 is hovering over object2. Is that possible in Scratch?

Offline

 

#2 2013-04-05 09:33:31

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Re: Object/Sprite hovering over Object

You could make a sprite shaped like a box. Then put that sprite in the area over the one object you want to have something hovering over.

Then make the box invisible by using the set [ghost] effect to 100 block. Make sure the box is small enough that to be touching it a sprite has to be completely overtop the one object you want it to be hovering over.

Then have the sound play when the one object/sprite is touching the box sprite you made. Make sense?

Offline

 

#3 2013-04-05 13:06:57

Roxiy
New Scratcher
Registered: 2013-03-31
Posts: 4

Re: Object/Sprite hovering over Object

dusty22 wrote:

Then have the sound play when the one object/sprite is touching the box sprite you made. Make sense?

Wouldnt you need to click on it as well? Or does it work differently with invisible objects?

Offline

 

#4 2013-04-05 17:38:58

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Re: Object/Sprite hovering over Object

Oh, I think I understand now. I'm not sure, generally in Scratch it seems to me when you're holding a sprite via the mouse it doesn't run its scripts or have normal properties. If you could have it move via the arrow keys or another method it'd definately work. I'm not sure about using the mouse though.

Try having the script cue from the Green Flag being clicked, and then have it run that script by checking to see if the mouse is being clicked with.

Like this:

when gf clicked
forever if <mouse down>
 if <touching [mouse-pointer v]> 
  if <touching object2?>
     play sound1 until done
   end
 end
end
Try something like that.

Last edited by dusty22 (2013-04-05 17:41:15)

Offline

 

#5 2013-04-05 18:08:05

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: Object/Sprite hovering over Object

when gf clicked
forever
 if <<touching [mouse]?> and <mouse down?>>
  repeat until <not<mouse down?>>  
   go to [mouse]
  end
  if <touching [object2]?>
   play sound
  end
 end
end

Offline

 

#6 2013-05-03 11:54:52

Roxiy
New Scratcher
Registered: 2013-03-31
Posts: 4

Re: Object/Sprite hovering over Object

Hello,

My little sister and I tried your scripts (xlk, dusty22), but it still only plays the sound when the player places Object1 on Object2 and then clicks on Object1 ...

I guess, i will now have to explain to my sister she must use the arrow keys instead...

Thank you all for your help!

Offline

 

Board footer