Page 71 - Learn To Program With Scratch
P. 71

ClickOnFace .sb2  If you want people to interact with a sprite, you could change its cos-
                          tume in response to a mouse click, as in the Click on Face application.
                          This application contains a single sprite, named Face, which has the five cos-
                          tumes shown in Figure 3-2. It uses the when this sprite clicked block (from
                          the Events palette) to tell the sprite when to switch costumes.




                                                               The five costumes of the Face sprite
                                                               Tell the Stage to change its backdrop.


                                                                 The four backdrops of the Stage
                                                               When the Stage switches to Stage4, glide to
                                                               the upper-right corner and back to the center.
                          Figure 3-2: The smiley face and the backdrop change whenever the sprite is clicked .

                             When you run this application, every time you click the mouse on the
                          face image, the image will change to the next one in the list. The script
                          also uses the switch backdrop to block to command the Stage to switch
                          randomly to one of its four backdrops. When the Stage switches to its
                          Stage4 image, the Face sprite detects this event (using the when backdrop
                          switches to trigger block from the Events palette). In this case, the face
                          makes a trip to the upper-right corner of the Stage and then returns to
                          the center.



                                                    try it out 3-1
            TrafficLight .sb2  The file TrafficLight.sb2 contains one sprite that has three costumes (named red,
                            orange, and green) and an incomplete script, as shown below . Complete the
                            application by adding the necessary wait blocks to create a realistic traffic light
                            animation .










                                                                  red  orange  green










                                                                                Looks and Sound   49

                                           www.it-ebooks.info
   66   67   68   69   70   71   72   73   74   75   76