Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Changement de couleur

Transcript

This add-on will create a sprite that changes colors when the mouse hovers over it, making it eye catching as window shoppers pass by your store front.

To start, click on “choose new sprite from library,” and add a new sprite. This project will use the Sun, but you can pick any sprite you’d like.

Next, make the sprite change colors. To start, drag a “change color effect by” block from the looks menu into your scripts editor. Click the block to see what it does.

That looks cool, but in this add-on the sprite should change colors only when it is touching the mouse pointer. To make that happen, use an “if-then” statement and a “sensing” block. Place an “if-then” statement around the “change color effect by” block. This block stack now reads: “if something happens, change the color effect of this sprite.” Next add the condition that must be met in the “if” portion of the “if-then” block in order for the sprite to change colors.

You want the sprite to change color when it touches the mouse, so add a “touching” block from the sensing menu. Drag out a “touching” block, and place it inside the “if-then” block. From the options in the dropdown menu, choose “mouse-pointer.”

Now this reads: if the sun is being touched by the mouse-pointer, then the color effect should change. Click on this block stack to test it.

Nothing happens! Your program needs to continuously check if the sprite is touching the mouse-pointer.

Add a Forever loop around the “if-then” block. Now test your code.

Great! Finally, add a “when green flag clicked” event block to run this code when your program starts! This is your chance to share your project with others and tell them how it works. Write clear instructions so any Scratch user can play with your project and make it work. Now it’s your turn: Add a new sprite, and create an if-then statement. Add a “touching mouse-pointer” sensing block, a forever loop, and a “change color effect by” block to make the sprite change colors when the mouse pointer touches it. Test your code, and ask a neighbor if you need any help.

Choisir une extension
Changement de couleur
Crée un lutin qui change de couleur quand le pointeur de la souris le survole.
Dériver
Crée un lutin qui effectue différentes actions en réponse à son entourage.
Surprise cachée
Code une surprise cachée dans ta vitrine.
Folie
Code ton lutin pour qu'il devienne fou quand le pointeur de la souris le touche.
Parlez-en (Défi)
Ajoute des lutins parlants dans ton programme.
Lutins filants (Défi)
Fais filer plusieurs clones à travers la scène.
arrow_backward Retour
Suivant arrow_forward
Instructions
Choisis ci-dessous une extension que tu veux créer.