Demo #4

Animating with layers and copyPixels.

How was this done? Essentially, the patterns and shapes are created by taking an image, changing it, and then putting the resulting image back through the whole system again.

The animation is driven by a timeout object which calls an update method. This update method typically looks like this:

on mUpdate (me)

  -- two layers are animated separately by two 'effect ojects'

  myEffect1.mUpdate(myImage1)

  myEffect2.mUpdate(myImage2)

  -- the two layers are then combined into the

  -- 'virtual stage' image

  myStagebuffer.copyPixels(myImage1, myDRect1, mySRect1, myOptions1)

  myStagebuffer.copyPixels(myImage2, myDRect2, mySRect2, myOptions2)

  -- the virtual stage image is then copied to the stage

  (the stage).image.copyPixels(myStagebuffer, myRect, myRect)

  -- the overlay image (eg the yellow cursor) is then added

  (the stage).image.copyPixels(myOverlay, myOverlayDRect, myOverlaySRect)

end



Note that the source images are passed to the effect objects by reference. The source image may be independant of each other, or one of them might point to the stage buffer - which is itself a combination of the two layers.

A second timeout object switches the effect objects at certain intervals, and sets up the source images and other parameters required by the new 'update' method.

First published 19/05/2005