⭐ 1.7 Parallelism
Parallelism means getting two or more things happening at the same time. For example, what changes when you split a simple sequence into two programs executing in parallel?
Figure 52: Parallelism – Two Sprites
Follow the steps:
• Add another sprite to your stage
• Create some code to make your second sprite do something
• Make sure you execute the code for the second sprite using the same control
as the first sprite
• You can keep adding sprites and putting code into each one, as long as they have the same control to start their activities the code executes in parallel.
Figure 53: Example of parallelism: Two sprites on the same stage.
PARALLELISM WITH TWO SPRITES
Make a copy of the blocks of code to use it with the second sprite. Go to the upper block and then right click. You will get a dropdown list of items. Select “Duplicate”.
Figure 54: Using duplicate to create a copy of blocks of code
When you select Duplicate you will get a new group of blocks, which is the same as the old set of blocks.
Figure 55: Drag to duplicate the blocks of code to the second sprite
When
you drag the duplicate to the second sprite, you are giving it the same
instructions and code. You can see that
all sprites are doing the same thing at the same time. However, you can also
change some of the instructions or values in the duplicated block. Parallelism is when two sets of instructions run
at the same time. However, these instructions can be the same or different.