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 Einen Farbwechsel programmieren

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.

Erweiterung auswählen
Einen Farbwechsel programmieren
Eine Figur erstellen, die die Farbe wechselt, wenn sie die Maus berührt.
Eine neue Figur hinzufügen
Eine Figur erstellen, die abhängig von ihrer Umgebung unterschiedliche Handlungen vornimmt.
Eine Überraschung verstecken
Eine versteckte Überraschung in eurem Schaufenster programmieren.
Verrückt spielen
Eure Figur so programmieren, dass sie ausflippt, wenn sie mit dem Mauszeiger berührt wird.
Kunden hinzufügen (Herausforderung)
Eurem Programm Figuren hinzufügen, die sich unterhalten.
Die Figuren über die Bühne schießen lassen (Herausforderung)
Eine Figur über die Bühne schießen lassen.
arrow_backward Zurück
Weiter arrow_forward
Anweisungen
Wählt unten eine Erweiterung aus, die ihr programmieren möchtet.