The Mouse-Over script is a very simple script which enables the Scratcher to change a sprite's appearance or function simply by moving the mouse over a trigger area or sprite. This is most commonly used for aesthetic appeal; however, this method can be applied to multiple scenarios.

Methods

There are many different ways of using this type of script. This tutorial will cover two using a sprite for each button, and two for a sprite that serves as many buttons.

Single Button Costume Changing

This script will cause the sprite to change to a different "highlighted" costume when touching the mouse. Nice and simple and good for menu buttons.

when flag clicked
forever
if <touching [mouse-pointer v]?> then
switch costume to [highlighted v]
else
switch costume to [normal v]
end

Single Button Graphic Effects

This script uses a different concept, it shall not change costume but in fact use graphical effects (in this case the color effect) to change its appearance, while touching the mouse-pointer, before reverting to its usual look.

Of course any effect one wishes to use can take place using this script, these are only examples.

when flag clicked
forever
if <touching [mouse-pointer v]?> then
set [color v] effect to (25)
else
set [color v] effect to (0)
end


Another example Is:

when flag clicked
forever
if <touching [mouse-pointer v]?> then
set [brightness v] effect to (25)
else
set [brightness v] effect to (0)
end

Multiple Buttons in One Costume

If multiple buttons are shown in a single costume in a single sprite, only the costume changing method is feasible. It is similar to the script above, except with more costumes, and more if clauses. A costume must be created showing each button highlighted, and one more with none highlighted.

when gf clicked
forever  
if <<(mouse y) > [30]> and <touching [mouse-pointer v]?>> then
switch costume to [first v]
else
if <<(mouse y) > [0]> and <touching [mouse-pointer v]?>> then
switch costume to [second v]
else
if <<(mouse y) > [-30]> and <touching [mouse-pointer v]?>> then
switch costume to [third v]
else
switch costume to [fourth v]
end
end
end

This script assumes three buttons, with the bottom at Y Position 30, 0, and -30, respectively. It senses if it is touching, and which one is selected, by use of the Mouse Y value.

Multiple Buttons Stamping

The other option for only using one sprite for multiple buttons is to stamp. A costume must be created for each button.

when gf clicked
clear
go to x: (0) y: (30)
switch costume to [first v]
clear graphic effects
repeat (3)  
stamp
change y by (-30)
next costume
end
set [color v] effect to (25)
forever  
if <<<(mouse y) > [25]> and <(mouse y) < [35]>> and <<(mouse x) > [5]> and <(mouse x) < [5]>>> then
go to x: (0) y: (30)
switch costume to [first v]
show
else
if <<<(mouse y) > [-5]> and <(mouse y) < [5]>> and <<(mouse x) > [5]> and <(mouse x) < [5]>>> then
go to x: (0) y: (0)
switch costume to [second v]
show
else
if <<<(mouse y) > [-35]> and <(mouse y) < [-25]>> and <<(mouse x) > [5]> and <(mouse x) < [5]>>> then
go to x: (0) y: (-30)
switch costume to [third v]
show
else
hide
end
end
end

This example first stamps the regular costumes in their positions. Then, when any of the stamps are being touched, the sprite goes to it, and adjusts its color without stamping. If none are, it hides.

Optionally, the graphical adjustments can be replaced with costume changing. Depending on the order of the costume, this may require the setup script to be adjusted.

Uses

This script has many different uses, however these are a few:

  • Improving the aesthetics (how good something looks) of a project
  • Letting a user know that an object can be clicked
  • Making a project seem more professional
  • Recreating menus that a user has seen in a video game