モーショントゥイーンを自動作成する.jsfl
Flash, JSFL ·モーショントゥイーンを自動作成する.jsflをとりあえず作ってみました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xjsfl.init(this); //init xJSFL | |
const STAR_NAME = "star"; | |
var dom = $dom; | |
var lib = $dom.library; | |
var tl = $timeline; | |
var context = Context.create(); | |
makeStar(); //星を作る | |
lib.addItemToDocument({x:100 , y:100}, STAR_NAME); //ステージに配置 | |
tl.createMotionTween(); //モーショントゥイーンを作成 | |
tl.insertKeyframe(29); //30フレーム目にキーフレームを挿入 | |
//30フレーム目のMCを変形させる | |
$('*') | |
.attr('position', [400,200]) | |
.attr('scale', [1, 0.5]) | |
.attr('rotation', 30) | |
.refresh(); | |
//星のMCを作る | |
function makeStar(){ | |
if( ! lib.itemExists(STAR_NAME)) | |
{ | |
lib.addNewItem('movie clip', STAR_NAME); | |
lib.editItem(STAR_NAME); | |
makeStarPath(5, 20, 40); | |
dom.selectAll(); | |
dom.setFillColor('#99CC3366'); | |
dom.setStroke('#003300AA', 0.5, 'solid') | |
context.goto(); | |
} | |
} | |
//星のパスを描画 | |
function makeStarPath(sideNum, inside, outside){ | |
var myPath = fl.drawingLayer.newPath(); | |
var radius, radians; | |
for (var i = 0; i <= sideNum * 2 ; i++) | |
{ | |
radius = (i%2) ? inside : outside; | |
radians = 360 * (i / sideNum / 2) * (Math.PI / 180) + (Math.PI * 1.5); // 星なので90度から描画開始 | |
myPath.addPoint(Math.cos(radians) * radius, Math.sin(radians) * radius); | |
//trace(Math.cos(radians) * radius, Math.sin(radians) * radius); | |
} | |
myPath.makeShape(); | |
} |
xJSFL | Context (class) を使いたかったが、バグがかなりあるようなのでかなりはまりました。無難に公式のAPI叩いた方がいいかも。 2012/6/10 追記:$timeline が用意されているようなので、それを使いました。
実行するとこんな感じになります。
次にやりたいこと
- 任意のフレームをモーショントゥイーン
- イージング
- 複数レイヤーで同時に自動作成
- グラフィック(またはMC)を作ってその中にタイムライン作成
- パーティクルのようなもの
- タイポグラフィー