前エントリの GryphOut クラスを使いつつ、回転・拡大・縮小するテキストのアニメーションを作ってみる。
サンプルで出力したフラッシュのswfファイル
サンプルコード
import com.anotherbigidea.flash.movie.*;
import com.anotherbigidea.flash.structs.*;
public class JavaSwfSample3 {
public static void main(String[] args) throws Exception {
final int width = 400;
final int height = 300;
// 縁
Shape border = new Shape();
border.defineLineStyle(5, new Color(0, 255, 0));
border.setLineStyle(1);
border.move(0, 0);
border.line(width, 0);
border.line(width, height);
border.line(0, height);
// テキスト
Shape text = new Shape();
text.defineLineStyle(1, null);
text.setLineStyle(1);
java.awt.Font font = java.awt.Font.decode(null).deriveFont(30.0f);
GryphOut.PathDrawer drawer = new GryphOut.SwfPathDrawer(text);
GryphOut go = new GryphOut();
go.setFont(font);
go.draw("helloこんにちは赤ちゃん!♪", 0, 0, drawer);
// テキストをアニメーションのオブジェクトへセット
MovieClip clip = new MovieClip();
Frame clipFrame = clip.appendFrame();
Instance inst = clipFrame.placeSymbol(text, 0, 0);
// テキストのアニメーション設定
for (int i = 0; i < 360; i += 3) {
//Transform matrix = new Transform(i * Math.PI / 180.0, 0.0, 0.0);
Transform matrix = new Transform(i * Math.PI / 180.0, i/50.0, i/50.0, 0.0, 0.0);
Frame f1 = clip.appendFrame();
f1.alter(inst, matrix, null);
}
// メインswf環境設定
Movie movie = new Movie();
movie.setWidth(width);
movie.setHeight(height);
movie.setBackColor(new AlphaColor(255, 255, 255, 0));
Frame movieFrame = movie.appendFrame();
// 縁をセット
movieFrame.placeSymbol(border, 0, 0);
// アニメーションのオブジェクトをセット
movieFrame.placeSymbol(clip, 100, 100);
movie.write("sample3.swf");
}
}
左縁の枠線がちゃんと表示されないのは、たぶんJavaSWFでは描画する座標を中心にして線幅を膨張させる仕様じゃないから。Java2Dと違う感じの仕様なので、そのへんを考慮しなきゃいけないのはちょっと使いにくい。
tags: zlashdot Java Flash Java JavaSWF
Posted by NI-Lab. (@nilab)