Animation
Adding animation
to your Flash movies is both fun and taxing. The key to animation is the SWFDisplayItem
object returned by the add()
function of your movie object. SWFDisplayItem
objects have a variety of functions that allow you to move, rotate, scale, and skew your objects easily. This next example demonstrates some basic animation:
$font = new SWFFont("Impact.fdb"); $text = new SWFText(); $text->setFont($font); $text->moveTo(300, 500); $text->setColor(0, 0xff, 0); $text->setHeight(200); $text->addString("Text is surprisingly easy"); $movie = new SWFMovie(); $movie->setDimension(6400, 4800); $displayitem = $movie->add($text); for($i = 0; $i < 100; ++$i) { $displayitem->rotate(-1); $displayitem->scale(1.01, 1.01); $movie->nextFrame(); } header('Content-type: application/x-shockwave-flash'); $movie->output();
Although that code is largely the same as a previous script, the $movie->add($text)
line has now changed so that the return value is captured and stored in $displayitem
.
The script then runs through a loop 100 times, each time calling rotate()
, scale()
, and nextFrame()
. Animation works by defining the initial state of the movie, advancing the frame, then specifying changes from the previous frame. In practice, this means you use nextFrame()
each time you want to move forward to the next frame of your Flash animation.
The rotate()
function takes a single parameter, which is the floating-point value of the amount to rotate your SWFDisplayItem
object from its current rotation. ...
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.