[心得] Tween class的method和event handler補充
Tween class的物件還有一些有用的method和event handler
之前打文打太急把它們給忘掉了~XD
本文最後有附上範例
Tween object可以用的method如下:
1.stop()
將tween motion暫停
2.resume()
將暫停的tween motion繼續執行
3.continueTo(endValue, duration)
設定新的endValue和duration
4.fforward()
指定property直接跳到endValue
5.rewind()
指定property直接跳回startValue
6.nextFrame()
tween motion(暫停時)往下一個階段邁進一步
7.prevFrame()
tween motion(暫停時)往上一個階段邁進一步
8.start()
tween motion重新執行一次
9.yoyo()
tween motion執行完畢的時候,會往回執行
easeIn會自動換成easeOut,反之亦然
Tween object可以用的event handler如下:
1.onMotionChanged
當指定產生tween motion的property值每一次被更新完後
2.onMotionFinished
當tween motion執行完畢時(property達到endValue)
3.onMotionStopped
當使用stop() method來停止tween motion的時候
4.onMotionResumed
當使用resume() method來繼續執行tween motion的時候
5.onMotionStarted()
當使用start()或者yoyo() method來重新執行tween motion的時候
一開始用new Tween()的時候並不會觸發這個event handler
所以我如果要一個場上名為my_mc的MovieCilp左右來回震盪
左邊界為10,右邊界為500,半個週期為2秒,並且在兩端點有平滑減緩效果
我可以寫如下的code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var motion:Tween = new Tween(my_mc, "_x", Regular.easeInOut, 10, 500, 2, true);
motion.onMotionFinished = function(){
this.yoyo();
};
這樣可以做出簡諧運動的效果
如果不是想要用三角函數參數式進一步操控的話
用這招達成比較省功夫唷~而且寫起來比較直覺一點
不用自己算什麼 振幅 週期 中心點 的
("_x = R*Math.sin(T) + D" 的 R, T, and D)
只要知道兩端點的位置和半個週期長就好了!!!
另外,想要做出斜的簡協運動,
只要用兩個Tween object在同一個MC上就搞定囉~
(藍字為 新增/修改 的code)
import mx.transitions.Tween;
import mx.transitions.easing.*;
var motion:Tween = new Tween(my_mc, "_x", Regular.easeInOut, 10, 500, 2, true);
var motion2:Tween = new Tween(my_mc, "_y", Regular.easeInOut,10, 500, 2, true);
motion.onMotionFinished = motion2.onMotionFinished = function(){
this.yoyo();
};
如何~?這樣不是方便多了嗎 =U=+
--
CJ Cat = Croa'J Cat = Cockroach Cat = 西街凱特 = 蜚蠊貓 = 蟑螂貓
Gallery http://cjcat2266.deviantart.com
MSN cjcat2266@hotmail.com
Yahoo cjcat2266@yahoo.com.tw
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.228.85.138
※ 編輯: cjcat2266 來自: 61.228.85.138 (07/25 12:25)
※ 編輯: cjcat2266 來自: 61.228.85.138 (07/25 12:46)
Flash 近期熱門文章
PTT數位生活區 即時熱門文章