Mouse-Over

Материал из Поле цифровой дидактики

The Mouse-Over script is a 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. It can be used for menu buttons.

whenclickedforeveriftouchingmouse-pointer?thenswitchcostumetohighlightedelseswitchcostumetonormalend

Single Button Graphic Effects

This script uses a different concept, it will 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.

whenclickedforeveriftouchingmouse-pointer?thensetcoloreffectto25elsesetcoloreffectto0end


Another example is:

whenclickedforeveriftouchingmouse-pointer?thensetbrightnesseffectto25elsesetbrightnesseffectto0end

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.

whenclickedforeverifmousey>30andtouchingmouse-pointer?thenswitchcostumetofirstelseifmousey>0andtouchingmouse-pointer?thenswitchcostumetosecondelseifmousey>-30andtouchingmouse-pointer?thenswitchcostumetothirdelseswitchcostumetofourthendendend

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.

whenclickederaseallgotox:0y:30switchcostumetofirstcleargraphiceffectsrepeat3stampchangeyby-30nextcostumeendsetcoloreffectto25foreverifmousey>25andmousey<35andmousex>5andmousex<5thengotox:0y:30switchcostumetofirstshowelseifmousey>-5andmousey<5andmousex>5andmousex<5thengotox:0y:0switchcostumetosecondshowelseifmousey>-35andmousey<-25andmousex>5andmousex<5thengotox:0y:-30switchcostumetothirdshowelsehideendendend

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