Effects with the Pixel Bender Toolkit – Part 8: Controlling the displacement filter with mouse positioning

来源:互联网 发布:淘宝乐高拼装玩具大全 编辑:程序博客网 时间:2024/05/17 02:10

Requirements

In this article, you'll add a type of interactivity that animates a Pixel Bender filter to correspond to changing mouse positions.

This is the eighth installment in this series of articles about using the Pixel Bender Toolkit to create visual effects with bitmap images. In the previous section, you learned how to update the displacement filter to enable it to move in all directions. You also updated the parameters to make the displacement filter effect more dramatic when you moved the slider controls.

In this section, you'll update the ActionScript code in the Flash file to control the displacement filter parameter with changing positions of the mouse.

Setting up the files

Before you begin, if you'd like to continue experimenting with the previous version of the project, you can add a second slider to control the float2 parameter that you just added to the Displacement filter. That process is fairly straightforward and it is always a good idea to practice when learning a new concept.

In this part of the series, we'll discuss adding another type of interactivity to control the filter effect; this time you'll track the placement of the cursor and use it to animate the displacement filter.

Before updating the ActionScript, set the file up in Flash in preparation for the code edits. Follow these steps:

  1. Launch Flash CS4 (or make it active if it is already open).
  2. Open the file named Exercise5.fla from the pixel_bender folder on your desktop.

    (If you are just beginning to follow along with this section and didn't complete the files in the previous parts of this series, download the sample files provided. Uncompress the ZIP file and save the contents into a folder named pixel_bender that you create on your desktop. Open the file named exercise8A.fla to begin following along at this point.)

  3. When you open the FLA file, you'll see a flower image and a slider control on the Stage.
  4. Choose Window > Actions to open the Actions panel (if it is not already open). Alternatively, expand the panel if it was open but collapsed.
  5. Select Frame 1 in the Timeline and review the code in the Script window. It should look similar to the ActionScript shown below: