Applying Special Effects to Costumes and Backgrounds

The next three looks code blocks, shown in Figure 10.7, apply to both sprites and the stage and can be used to apply and clear different graphical special effects.

Figure 10.7. These code blocks allow you to set and clear different graphics effects on sprites.


The first and second code blocks shown in Figure 10.7 select and then apply one of the following special effects to a sprite’s costume or to the stage’s background.

  • Color. Modifies the costume or background’s color.

  • Fisheye. Magnifies a portion of a costume or background.

  • Whirl. Twists and distorts a portion of a costume or background.

  • Pixelate. Displays a sprite or background at a lower resolution than the resolution at which the image was created.

  • Mosaic. Creates an image made up of repeated instances of a sprite or background.

  • Brightness. Modifies an image by increasing or decreasing its intensity of light.

  • Ghost. Fades the appearance of a costume or background to make it look transparent.

An example of each of these graphic effects on a sprite is shown in Figure 10.8.

Figure 10.8. A demonstration of how special effects affect a sprite.


To develop a better understanding of how to work with these two code blocks, let’s look at a couple of examples. In this first example, a sprite’s appearance is changed by executing a loop four times. Each time the loop executes, it applies the ghost effect to the sprite to which it belongs.

Note that the value specified in the input field for the code block in the previous script is 25, which represents a percentage value. As such, for each of the four times that the loop repeats, the sprite fades away until at the end of the last execution of the loop, the sprite completely disappears.

This second example applies the whirl special effect to its sprite. Specifically, it begins by clearing any previous whirl effect that may have been applied to the sprite. Then, over a period of four seconds, it slowly modifies the appearance of the sprite by applying an increased application of the whirl effect. A one-second pause then ensues, and the sprite is returned to its original state.

The last looks code block restores a costume or background back to its original appearance regardless of how many different graphical effects may have been applied to it. For example, the following statement demonstrates how to restore a costume or background’s appearance when the green flag button is pressed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.167.114