Page 84 - TrackpadV1.0_C5_Flipbook
P. 84

CONTROLLING THE MOVEMENT OF A SPRITE


                  We can control a sprite by using the sensing block.


                  SENSING BLOCK
                  The Sensing block gives an answer when asked a question. Sensing blocks are

                  colour-coded with a light-blue shade and are used to detect different sprites and
                  elements of a project including the edge of the stage. They control the movement of the
                  sprite in a better manner. The table given below outlines the code blocks that fit into this
                  category:




                            Blocks                                           Functions



                                                 It checks if its sprite is touching the mouse-pointer, the edge,
                                                 or another sprite. If the sprite is touching the  selected object,
                     touching mouse-pointer  ?
                                                 the block returns a true value; if it is not, it returns ‘false’. It is
                                                 used with an if-then block.

                                                 It checks whether its sprite is touching a specified colour. If
                      touching color  ?
                                                 it is, the block returns ‘true’. It is used with an if-then block.

                                                 It makes an input box (with the specified text above it) and
                                                 displays it at the bottom of the screen. The user can then
                    ask  What’s your name?  and wait
                                                 enter  text  into  it  and  submit  it.  The input  is  stored  in  an
                                                 Answer block after that.

                                                 It holds the most recent text entered with the Ask () and Wait
                        answer
                                                 block.
                                                 It checks if the specified key is pressed. If the key is being
                     key  space   pressed?
                                                 pressed, the block returns ‘true’; if it is not, it returns ‘false’.

                  Let us create a program and hear your cat meow.

                  Step  1     Click the Event button to show the Event blocks.                         when     clicked

                  Step  2     Click the Motion button to show the Motion blocks.                     move 100    steps

                  Step  3       Drag a Move 10 steps block to the code area and change
                              the value to 100.

                  Step  4     Click the Control Button to show the Control blocks.                      if      then

                  Step  5     Drag an if…then block to the code area.



                   82   Trackpad (Version 1.0)-V
   79   80   81   82   83   84   85   86   87   88   89