přejít na obsah přejít na navigaci

Linux E X P R E S, Rotation around center with SWFMILL and MTASC

Konference Cloud computing v praxi

Rotation around center with SWFMILL and MTASC

I had to make a simple swf with an object rotating around his center. But ActionScript 2 (MTASC) set by default the registration point (rotation point or pivot) into the top left corner. How can I rotate it around its center with my open source tools? In Adobe Flash it's quite easy but I can do it even with SWFMILL!


reklama

Firstly I made a simple object in Inkscape.

Picture_1.png

I exported it as a png image file and I wrote an xml file for SWFMILL:

<?xml version="1.0" encoding="utf-8" ?>
<movie width="300" height="300" framerate="30">
<background />
<clip import="classes.swf" />
<frame>
<library>
<clip id="box.png" import="assets/box.png" class="Box" />
</library>
<place id="box.png" name="_box" x="100" y="100" depth="1" />
</frame>
</movie>

A little explanation: My object is actually imported into the stage and receive a “Box” class on it.

Here is my “Box” class written in ActionScript 2:

class Box extends MovieClip
{

function Box ()
{
}


function onEnterFrame ()
{
this._rotation += 5;
}


}

Two CLI commands to compile my swf animation:

mtasc -header 1:1:30 -swf classes.swf Box.as
swfmill simple classes.xml ../build/box.swf

Let’s look at my animation:

But the object is rotating about the top left corner! In Adobe Flash I can set position of the registration point anywhere but how can I do it with SWFMILL?

I must do a little hack. With SWFMILL I embed the object into another MovieClip. The parent object still continues to rotate around its top left corner. But if I change now position of the embedded object, which is static, it makes an effect change of the rotation point! If I want for example to rotate some object around its center the embedded object must have its x and y coordinates set to the negative half value of its width and height dimensions.

schema.png

For example my box has 91 pixels of width and 91 pixel of height. I set its x coordinates to -45.5 px and its y coordinates to -45.5 px.

My repaired XML file:

<?xml version="1.0" encoding="utf-8" ?>
<movie width="300" height="300" framerate="30">
<background />
<clip import="classes.swf" />
<frame>
<library>
<clip id="box.png" import="assets/box.png" />
<clip id="box" class="Box">
<place id="box.png" x="-45.5" y="-45.5" depth="2" />
</clip>
</library>
<place id="box" name="_box" x="100" y="100" depth="1" />

</frame>
</movie>

I compile a new swf with my favourite commands:

mtasc -header 1:1:30 -swf classes.swf Box.as
swfmill simple classes.xml ../build/box.swf

As you can see, I rotate now the parent MovieClip. It continues to rotate about its top left corner. But the embedded object with its negative coordinates looks like rotating around its center.

Now I can change dynamically the registration point for further animation with SWFMILL. It's quite easy even with this open source tool, isn't it?

Nahoru

Top články z OpenOffice.cz

Luděk Janda


  • Distribuce: macos x, slackware