Thursday, 4 January 2018

18) Moving sprite using keyboard and mouse

Moving sprite using keyboard and mouse
A sprite is animated using different programming blocks. The sprite can be moved by using keyboard as well as by using mouse.
Create a movement of a sprite 
We can move a sprite in forward or backward direction in Stage Area with the help of Motion button. The steps to move a sprite are:
  1. Click on the Motion button. The various programming blocks appear in the Blocks Palette.
  2. Click and drag move 10 steps to the Script Area.
  3. Click on the value 10 and change the value from 10 to 100.
  4. Double click on the programming statement to observe the motion. The Sprite moves 100 steps in forward direction in stage area.
Note: If a negative number is written in value area eg -100, the sprite moves in backward direction.
Rotating a Sprite
A Sprite can be rotated in clockwise or anticlockwise direction by any degree. The steps to rotate a sprite are:
  1. Drag the programming block turn 15 degrees to previous script.
  2. Change the default value 15 to 60.
  3. Double click on the programming statement to observe the motion. The Sprite moves 100 steps in forward direction and turns by 60 degrees in stage area.
The rotation style should be selected according to the following blocks:
   
Control the movement with keyboard
To control the movement of sprite with the help of keyboard we have to use many programming blocks. The steps to control sprite with arrow buttons are as follows:
  1. Click on Control button. The various programming blocks appear in the Blocks Palette.
  2. Click and drag when space key pressed.In space option choose any key e.g. up arrow, down arrow, A, B and choose the required operation on press of that key. As in the given activity choose right arrow and then move 10 steps.
  3. On click of right arrow, sprite moves 10 steps in forward direction till the right arrow key is pressed or stage corner is reached.


Control movement with mouse
To control the movement of sprite with the help of a mouse different programming blocks are used. To demonstrate it, the following activity is planned:
  1. Click on Control button and drag Flag clicked. Choose  forever block to continue the movement.
  2. Choose from Motion button, point towards and in the drop down arrow choose mouse pointer.
  3. Move the sprite by dragging move 3 steps. On click of green flag on top right corner, sprite follows the mouse pointer and moving with it.
                   Flag clicked  
                   point towards   

No comments:

Post a Comment

1) Introduction to Email

Introduction to Email Introduction Communication, the transfer of information, has been the key element needed ...