利用GreenSock Tweening Platform製作動畫

因為馬老師剛開始利用程式製作補間動畫的Class是Tweener,所以前面介紹了很多篇這方面的文章,但當然這方面的Class不是只有Tweener而已,所以接下來介紹一個目前發展起來比Tweener還要棒很多的Class,它是由GreenSock研發的Tweening Platform(補間平台),其中包含了:「TweenNano」、「TweenLite」、「TweenMax」、「TimelineLite」、「TimelineMax」。

為什麼說他發展得比較好呢?除了Tweener能做到的幾乎它都可以以外,也因為Tweener已經停止開發,所以未來將不會有新增的功能,但TweenMax還在不斷的更新中,在官網還有以下的比較案例:

各種補間動畫 速度測試

從上面的案例可以看出來利用GreenSock所研發的Tweening Platform的執行效能會比其他的好(FPS越高越好),所以接下來就來看看GreenSock Tweening Platform的簡介。

TweenNano、TweenLite與TweenMax算是同樣功能,但在製作後檔案容量是TweenNano<TweenLite<TweenMax,也就是說利用TweenNano所製作出來的動畫容量是最小的,舉個例來說,像這樣的動畫效果,TweenNano製作後swf大小為:5KB、TweenLite:8KB、TweenMax:21KB,不過在功能上面也是TweenNano<TweenLite<TweenMax,也就是說TweenMax可以掌控的效果比較多,也更具有彈性,例如:TweenNano就沒有辦法執行:pause()、play()、restart()…等,而TweenLite沒辦法執行:貝茲曲線運動、濾鏡…等,所以要用哪個版本的Tween,端看想要製作的動畫效果來考量,官方也有針對此三者製作比較表供大家參考。

另外TimelineLite和TimelineMax算是同樣功能,但看到後面的英文單字應該可以了解與上述具有相同的關聯,而這方面的Class是可以掌握時間軸上面的變化,在Tweener中,我們只能用Delay來控制動畫先後順序,而在GreenSock所研發的Tweening Platform中則可以利用TimlinelineLite或TimelineMax來處理。

馬上來介紹有關這個Class的一些使用方式,與Tweener一樣的是必須先下載備用載點),然後在需要使用的Flash檔案中import該Class,下載解壓後會有以下的資料夾:

  • badges:GreenSock圖標。
  • com:主要Class資料夾。
  • demo_swfs:裡面有很多swf的展示,對於想要了解本Class非常有幫助。
  • docs:參考文件。

在import時,看你想要使用的Class來import,例如需要使用TweenNano則:

import com.greensock.TweenNano;

若需同時使用TweenLite和TweenMax則:

import com.greensock.TweenLite;
import com.greensock.TweenMax;

想偷懶,則:(別擔心,Flash只會內嵌有使用到的部分)

import com.greensock.*;

至於製作補間的程式碼,其實官方就有製作swf來給大家參考,這邊也把官方的範例放進來給大家參考:

基礎動畫製作 範例檔

上面的案例可以讓你測試動畫效果,下方也會產生該段動畫的程式碼供你使用,實在是非常方便。另外關於Tween的語法也可以改成下面這種版本:

TweenLite.from(mc, 1.5, {y:0, alpha:0});

一個是告訴動畫要去哪,另一個是告訴動畫要從哪開始變化,關於Tweener可以使用的delay、onComplete、onStart、onUpdate…等,這個Class也都可以使用,例如:

TweenLite.to(mc, 1.5, {x:100, ease:Elastic.easeOut, delay:1, onComplete:okFn});
function okFn() {
    trace("動畫執行完畢");
}

這個Class還有很多特別的動畫效果,例如:濾鏡、短距離旋轉、貝茲曲線、聲音、色彩變換…等,大家也可以參考官方製作的swf來參考動畫效果與取得程式碼:

特殊動畫效果 範例圖

在動畫控制上面可以使用如下的程式碼來控制動畫:

var myTween:TweenLite = new TweenLite(mc, 1, {x:100, y:100});

myTween.pause();
//暫停動畫播放

myTween.resume();
//恢復動畫播放

myTween.reverse();
//反向播放

myTween.play();
//播放動畫

myTween.restart();
//重播動畫

myTween.invalidate();
//移除補間並使元件恢復原始狀態

myTween.kill();
//清除補間動畫

TweenLite.killTweensOf(mc);
//清除所有物件之補間動畫

以上是有關GreenSock Tweening的介紹,接下來介紹有關TimelineLite與TimelingMax的部分。

就像上面有提到在Tweener中我們如果希望三個元件在不同的時間點開始移動,就只能使用delay或是另外寫程式來控制,現在我們可以使用Timeline相關的Class來完成這樣的任務,甚至還可以讓時間軸倒著播放也沒問題,以下就是有關TimelineLite的官方範例:

TimelineLite 範例檔

另外是TimelineMax的範例檔,供大家參考:

TimelineMax 範例檔

以上就是針對GreenSock Tweening Platform大致的介紹,建議有空可以前往官網鑽研更多其他的功能,另外其實GreenSock另外還有TransformManagerLoaderMax,各位也可以先參考官網文章或是未來再跟大家分享我的使用心得。

註:本範例所使用的範例版權屬於GreenSock公司所有。

You may also like...

18,303 Responses

  1. Профессиональный сервисный центр по ремонту принтеров в Москве.
    Мы предлагаем: ремонт принтеров москва
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  2. Профессиональный сервисный центр по ремонту принтеров в Москве.
    Мы предлагаем: диагностика и ремонт принтеров
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  3. weed vape表示:

    I absolutely love your website.. Great colors & theme. Did you make this website yourself? Please reply back as I’m wanting to create my very own blog and would love to know where you got this from or just what the theme is called. Thanks!

  4. My web blog Daycare Near Me – Find The Best Daycares Near You
    (http://incentiveaustrailia.com)

  5. weed vape表示:

    Oh my goodness! Awesome article dude! Many thanks, However I am encountering problems with your RSS. I don’t understand why I am unable to subscribe to it. Is there anyone else getting the same RSS problems? Anyone who knows the answer will you kindly respond? Thanks!!

  6. Stephengen表示:

    http://vgrsansordonnance.com/# Viagra pas cher livraison rapide france

  7. Stephengen表示:

    http://vgrsansordonnance.com/# Viagra femme sans ordonnance 24h

  8. Профессиональный сервисный центр по ремонту принтеров в Москве.
    Мы предлагаем: срочный ремонт принтеров
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  9. DouglasHoapy表示:

    1xBet Code https://idematapp.com/wp-content/pages/1xbet_promo_codes_free_bonus_offers.html
    1xBet codes refer to the alphanumeric strings provided by the platform or its partners, which can be used to claim bonuses such as free bets, deposit matches, or free spins. These codes are often shared through promotions, social media, or affiliate websites.

  10. Профессиональный сервисный центр по ремонту объективов в Москве.
    Мы предлагаем: ремонт объектива цена
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  11. DouglasHoapy表示:

    1xBet Promo Code Bonus https://actuchomage.org/includes/wkl/code_promo_69.html
    1xBet promo codes can unlock various bonuses, including deposit matches, free bets, and free spins. These codes are a great way to boost your bankroll and increase your chances of winning.

  12. HeathZex表示:

    pharmacie en ligne: Pharmacies en ligne certifiees – pharmacies en ligne certifiГ©es

  13. Stevecoalo表示:

    Look of the Week: Forget the naked dress, Kendall Jenner makes the case for underwear as outerwear
    kraken тор

    On Monday, Kendall Jenner stepped out onto the L’Oreal Paris womenswear runway in a scarlet red Mugler gown that might have looked familiar to anyone with a sharp memory of 1999.

    The front of the dress was slashed open across Jenner’s right shoulder, exposing a matching denier bra. The peekaboo moment conjured up memories of another example of fashionable flashing: Lil’ Kim’s purple embellished jumpsuit at the VMAs 26 years earlier. On the red carpet, Kim’s left breast was almost entirely revealed by an asymmetrical cut — a mirror image of Jenner’s neckline — save for a matching purple nipple pasty.
    Jenner’s Mugler moment was just the latest example of a resurging tendency for underwear as outerwear. At the Nensi Dojaka runway show in London earlier this month, boxy blazers were shrugged over strappy bras while paneled bustiers in sheer fabric were paired with capri trousers and reimagined as going out tops. Brasseries were even left exposed to the elements at Erdem — a departure for a house beloved by both British acting royalty (Kristen Scott Thomas) and actual royalty (the Duchess of Cambridge). Dolce & Gabbana got the memo, too, showing satin corsets, garter belts and Madonna-esque cone bras at Milan Fashion Week on Saturday. Florence Pugh even wore one of the label’s risque designs in her first British Vogue cover last week — the circle neckline of her puff-shouldered black dress scooping just above the belly button, acting as a full-frontal frame for her bra.
    But the trend extends beyond just the runways. During the first performance of her “Short n’ Sweet” tour on Monday, singer Sabrina Carpenter took to the stage in a custom Victoria’s Secret bodysuit and stockings. Hand-adorned with over 150,000 crystals, the strapless pink lace-trimmed leotard took over 140 hours to make. On Monday,YouTube star and singer Jojo Siwa inverted the fad by donning a codpiece for a headline-grabbing cover shoot with LadyGunn magazine. The 15th century undergarment was bedazzled with flesh-colored gemstones.

  14. Профессиональный сервисный центр по ремонту плоттеров в Москве.
    Мы предлагаем: починить плоттер
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  15. Профессиональный сервисный центр по ремонту МФУ в Москве.
    Мы предлагаем: ближайший ремонт мфу
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  16. Texas Capital (TCBI) Down 9.8 Since Final Earnings Report: Can It Rebound?

  17. Bracingly citrusy and effectively balanced daiquiris are only $7, as are the home Negronis and cognac-spiked French 75s.

  18. For the Hildebrandt brothers, the illustrations are virtually all the time accomplished utilizing acrylic paint in a really giant format.

  19. It can be very difficult, given our peculiar thinking, to work out why we just like the boots that we like.

  20. Divide the gamers into two groups, and have every crew stand about 50 ft apart, arms linked.

  21. The lyrics, “There’s got to be a morning after, If we will hold on by means of the night,” remind us that even within the darkest of occasions, there is always a glimmer of hope.

  22. The perfect journey insurance plans embrace beneficial advantages for journey cancellation, trip interruption, trip delay, medical expenses, medical evacuation and baggage loss.

  23. Remember that most charge-for-service plans do not cowl these visits, however managed care plans do.

  24. The final person must toss the ball to the starter, after which the ball must make an similar orbit around the circle again, following the same passing pattern.

  25. 存つ表示:

    It’s a small contact, however it can be very efficient in the fitting circumstances.

  26. Searching for the best journey sneakers for women is an overwhelming job.

  27. Order your uggs now and save on transport.

  28. Although the plan comes with a $700 billion price tag, the eventual cost might be even larger.

  29. Extreme coordination problems could stem from something as seemingly trivial or innocuous as an organization having a multi-ground workplace.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。