Frame-Animated Images With PHP And Ming

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jusa
Forum Newbie
Posts: 1
Joined: Wed Jan 16, 2008 7:51 am

Frame-Animated Images With PHP And Ming

Post by Jusa »

Hi,

I'm basically trying to implement sprites that display frame-animated images in PHP and Ming (the PHP Flash library), but I can't seem to figure out how to do it.

For this simple experiment I have two different jpg images and I'd like to have an SWFSprite object which alternatingly displays one of them for a while before switching back.

My code looks similar to this. This makes the ball.jpg blink and display for 25 iterations of the drawing loop but the box.jpg image doesn't show at all.

Code: Select all

 
$movie = new SWFMovie();
$movie->setDimension(640, 480);
$movie->setBackground(0xf5, 0xf5, 0xf5);
$movie->setRate(20);
 
$ball = new SWFBitmap(fopen('ball.jpg', 'r'));
$box = new SWFBitmap(fopen('box.jpg', 'r'));
$switch = 0;
 
$sprite = new SWFSprite();
$shape = $sprite->add($ball);
$s = $movie->add($sprite);
$s->moveTo(10, 10);
 
for($i=0; $i<50; $i++)
{
    if($i == 25)
    {
        if($switch == 0) {
            $sprite->remove($shape);
            $shape = $sprite->add($box);
            $swicth = 1;
        }
        else {
            $sprite->remove($shape);
            $shape = $sprite->add($ball);
            $switch = 0;
        }
    }
    
    $sprite->nextFrame();
    $movie->nextFrame();
}
 
$movie->save("animation.swf");
Any help is appreciated :)
Post Reply