利用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...

30,316 Responses

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

  2. GarrettMom表示:

    gore siteler [url=http://casibom1st.com/#]casibom giris[/url] bet casino casibom1st.shop

  3. RobertCex表示:

    bahis siteleri deneme bonusu: lisansl? casino siteleri – lisansl? casino siteleri casinositeleri1st.com

  4. KevinInalm表示:

    Why there’s a huge collection of vintage cars stored in the middle of the desert
    base bridge
    Back at the turn of the 21st century, Qatar was a country with few cultural attractions to keep visitors and residents entertained. Yet the Sheikh Faisal Bin Qassim Al Thani Museum — known as the FBQ Museum — was a place that most people visited as an alternative to the then-still rather ramshackle National Museum of Qatar.

    You had to make an appointment, and drive out into the desert, getting lost a few times along the way, but then you were welcomed to the lush Al Samriya Farm with a cup of tea and some cake. The highlight was being allowed into a space crammed full with shelves and vitrines holding all sorts of eclectic artifacts from swords to coins — with the odd car and carriage standing in the grounds.

    It wasn’t necessarily the kind of museum you’d find elsewhere in the world, but it was definitely a sight that needed seeing.

    Today, it has grown and now claims to be one of the world’s largest private museums. It holds over 30,000 items, including a fleet of traditional dhow sailboats, and countless carpets. There’s also an entire house that once stood in Damascus, Syria.

    There are archaeological finds dating to the Jurassic age, ancient copies of the Quran, a section that details the importance of pearling within Qatar’s history, and jewelry dating to the 17th century.

    There are also items from 2022’s FIFA World Cup in Qatar including replica trophies, balls used in the games, entry passes, football jerseys and even shelves full of slightly creepy dolls and children’s plush animals.

    Some of the more disturbing exhibits include various items of Third Reich paraphernalia in the wartime room, and, strangely enough, several showcases of birds’ legs with marking rings on them. Basically, whatever you can think of, you have a very good chance of finding it here.

    Rumor even has it that behind a locked door is a room filled with the late Princess Diana’s dresses and other memorabilia, accessible only to a select few visitors. Another door hides a room, no longer open to the public, filled with collectibles of the late Saddam Hussein.

  5. RobertCex表示:

    grand pasha bet: casibom giris – bedbo casibom1st.com

  6. Sazrxyq表示:

    Хочу поделиться своим опытом по заказу аттестата ПТУ. Думал, что это невозможно, и начал искать информацию в интернете по теме: купить аттестат за 11, купить диплом о переподготовке, купить диплом об окончании колледжа, купить диплом о среднем специальном образовании гознака, купить аттестат об окончании школы. Постепенно углубляясь в тему, нашел отличный ресурс здесь: proffdiplomik.com/diploms/diplom-bakalavra-2014-2017-kirzhach

  7. Weldonsib表示:

    gГјvenilir oyun siteleri: casibom – canlД± bahis siteleri casibom1st.com

  8. Weldonsib表示:

    slot casino siteleri: casino siteleri – lisansl? casino siteleri casinositeleri1st.com

  9. Diplomi_wbEa表示:

    Заказать диплом о высшем образовании!
    Мы готовы предложить документы университетов, расположенных на территории всей Российской Федерации.
    diplom-ryssia.com/kupit-diplom-s-registratsiej-v-reestre-bistro-i-nadezhno-3/

  10. LloydInilm表示:

    Tesla is bringing its electric cars to oil-rich Saudi Arabia amid falling global sales
    aperture finance
    Tesla will start selling its electric vehicles in Saudi Arabia, entering the Gulf region’s largest economy as the company’s global sales are sliding and CEO Elon Musk courts controversy with his role in the US government.

    The carmaker announced Wednesday that it would host a launch event in the kingdom on April 10, where it will showcase its EVs. Attendees will also have the chance to “experience the future of autonomous driving with Cybercab and meet Optimus, our humanoid robot, as we showcase what’s next in AI and robotics,” Tesla (TSLA) said.

    Tesla may struggle to gain market share in oil-rich Saudi Arabia as EVs make up a little over 1% of all car sales in the country, according to a report by consultancy PwC published in September.
    Tesla’s entry into the new market comes as the company fights battles on several fronts.

    Last year, it recorded the first annual decline in sales in its history as a public company, posting a drop of 1%.

    The company is facing intensifying competition in China, the world’s largest auto market. On Tuesday, BYD, a Chinese maker of electric and hybrid cars, reported $107 billion in annual sales for 2024, beating the near-$98 billion notched by Tesla.

    And last week, BYD unveiled an ultra-fast charging system, which it said was capable of adding 250 miles (402 km) of range in just five minutes, easily outdoing Tesla’s charging technology. Tesla’s Superchargers take 15 minutes to charge an EV, providing a range of 200 miles.

    Tesla has also suffered slumping sales in Europe. In February, the carmaker sold around 40% fewer vehicles on the continent compared with the same month in 2024, according to the European Automobile Manufacturers’ Association.

  11. RobertCex表示:

    caxino: casibom 1st – bahis siyeleri casibom1st.com

  12. Davidvew表示:

    While the Cumberland sample may contain longer chains of fatty acids, SAM is not designed to detect them. But SAM’s ability to spot these larger molecules suggests it could detect similar chemical signatures of past life on Mars if they’re present, Williams said.
    convex finance
    “Curiosity is not a life detection mission,” Freissinet said. “Curiosity is a habitability detection mission to know if all the conditions were right … for life to evolve. Having these results, it’s really at the edge of the capabilities of Curiosity, and it’s even maybe better than what we had expected from this mission.”

    Before sending missions to Mars, scientists didn’t think organic molecules would be found on the red planet because of the intensity of radiation Mars has long endured, Glavin said.
    Curiosity won’t return to Yellowknife Bay during its mission, but there are still pristine pieces of the Cumberland sample aboard. Next, the team wants to design a new experiment to see what it can detect. If the team can identify similar long-chain molecules, it would mark another step forward that might help researchers determine their origins, Freissinet said.

    “That’s the most precious sample we have on board … waiting for us to run the perfect experiment on it,” she said. “It holds secrets, and we need to decipher the secrets.”

    Briony Horgan, coinvestigator on the Perseverance rover mission and professor of planetary science at Purdue University in West Lafayette, Indiana, called the detection “a big win for the whole team.” Horgan was not involved the study.
    “This detection really confirms our hopes that sediments laid down in ancient watery environments on Mars could preserve a treasure trove of organic molecules that can tell us about everything from prebiotic processes and pathways for the origin of life, to potential biosignatures from ancient organisms,” Horgan said.

    Dr. Ben K.D. Pearce, assistant professor in Purdue’s department of Earth, atmospheric, and planetary sciences and leader of the Laboratory for Origins and Astrobiology Research, called the findings “arguably the most exciting organic detection to date on Mars.” Pearce did not participate in the research.

  13. RobertCex表示:

    slot casino siteleri: deneme bonusu veren yeni casino siteleri – lisansl? casino siteleri casinositeleri1st.com

  14. JasonDaT表示:

    Arctic auroras
    ethena
    For getting around during winter, the Inuit here nowadays prefer snowmobiles, although they still keep their sled dogs. During winter they’ll offer intrepid visitors, wrapped up warm against the deep-freeze temperatures, dog-sledding jaunts. These can last either an hour or be part of expeditions over several days, sometimes with the added experience of learning how to build an igloo. Sisimiut on the west coast and Tasilaq in the southeast are active winter centers for dog sledding.

    Winter’s most stellar attraction, though, is northern lights watching. With little urban light pollution, Greenland is a dark canvas for spectacular displays, and aurora borealis-watching vacations are becoming more popular.

    Staying outdoors, Greenland is developing a reputation among adventure enthusiasts: from long-distance skiing expeditions and heliskiing on the icecap to hiking the 100-mile-long Arctic Circle Trail from Kangerslussuaq, where firearms need to be carried for warning shots in case of polar bear encounters.

    Life is definitely changing here. The climate crisis is eating away at its icecap and Greenland may well end up as a pawn in a game of geopolitical chess. But for now, the bright glare of international attention should shine a favorable light on one of the wildest travel destinations on Earth.

    Travel writer Mark Stratton is an Arctic specialist who has traveled to Greenland six times and counting. He’s marveled at the aurora borealis, sailed to Disko Island, dog-sledded with the Inuit, and once got stuck in an icefloe.

  15. 1win_rlmt表示:

    1вин сайт официальный https://1win6043.ru .

  16. Chesterwib表示:

    Curiosity has maintained pristine pieces of the Cumberland sample in a “doggy bag” so that the team could have the rover revisit it later, even miles away from the site where it was collected. The team developed and tested innovative methods in its lab on Earth before sending messages to the rover to try experiments on the sample.
    changelly exchange
    In a quest to see whether amino acids, the building blocks of proteins, existed in the sample, the team instructed the rover to heat up the sample twice within SAM’s oven. When it measured the mass of the molecules released during heating, there weren’t any amino acids, but they found something entirely unexpected.

    An intriguing detection
    The team was surprised to detect small amounts of decane, undecane and dodecane, so it had to conduct a reverse experiment on Earth to determine whether these organic compounds were the remnants of the fatty acids undecanoic acid, dodecanoic acid and tridecanoic acid, respectively.

    The scientists mixed undecanoic acid into a clay similar to what exists on Mars and heated it up in a way that mimicked conditions within SAM’s oven. The undecanoic acid released decane, just like what Curiosity detected.

    Each fatty acid remnant detected by Curiosity was made with a long chain of 11 to 13 carbon atoms. Previous molecules detected on Mars were smaller, meaning their atomic weight was less than the molecules found in the new study, and simpler.
    “It’s notable that non-biological processes typically make shorter fatty acids, with less than 12 carbons,” said study coauthor Dr. Amy Williams, associate professor of geology at the University of Florida and assistant director of the Astraeus Space Institute, in an email. “Larger and more complex molecules are likely what are required for an origin of life, if it ever occurred on Mars.”

  17. Dnrtyzm表示:

    Мы изготавливаем дипломы любой профессии по приятным тарифам. Мы можем предложить документы техникумов, которые находятся на территории всей России. Документы печатаются на бумаге высшего качества. Это позволяет делать настоящие дипломы, не отличимые от оригиналов. socialnetwork.cloudyzx.com/read-blog/151782_kupit-diplom-cherez-reestr.html

  18. Weldonsib表示:

    sweet bonanza: sweet bonanza demo – sweet bonanza sweetbonanza1st.shop

  19. BradyGem表示:

    bet gГјncel giriЕџ: casibom giris adresi – tГјrkiye yasal bahis siteleri casibom1st.com

  20. Jamesalulk表示:

    ‘For the public to enjoy’
    [url=https://web-keplr.com]keplr wallet[/url]
    The museum’s history starts in 1998, when Sheikh Faisal Bin Qassim Al Thani opened a building to the public on his farm some 20 kilometers (12 miles) north of Qatari capital Doha.

    A distant relative of Qatar’s ruling family, founder and chairman of Al Faisal Holdings (one of Qatar’s biggest conglomerates), and a billionaire whose business acumen had him recognized as one of the most influential Arab businessmen in the world, Sheikh Faisal had already amassed a substantial private collection of historically important regional artifacts, plus a few quirky pieces of interest, allowing visitors an intimate look into Qatari life and history.

    In an interview with Qatari channel Alrayyan TV in 2018, Sheikh Faisal said that the museum started as a hobby.

    “I used to collect items whenever I got the chance,” he said. “As my business grew, so did my collections, and soon I was able to collect more and more items until I decided to put them in the museum for the public to enjoy.”

    His private cabinet of curiosities has since evolved into a 130-acre complex. Through the fort-like entrance gate lies an oryx reserve, an impressive riding school and stables, a duck pond and a mosque built with a quirky leaning minaret. There’s now even a five-star Marriott hotel, two cafes and the Zoufa restaurant serving modern Lebanese cuisine.

    Of course, there’s also the super-sized museum, with a recently-opened car collection housing everything from vintage Rolls-Royces to wartime Jeeps and colorful Buicks. Outside you’ll find peacocks roaming the grounds, and signs warning drivers to be aware of horses and ostriches.

    Visitors to the FBQ museum are free to explore the grounds and can even enter the stables to pat the horses.

  21. ScottTaw表示:

    Iceberg flotillas
    debridge finance
    Located on the west coast, Ilulissat is a pretty halibut- and prawn-fishing port on a dark rock bay where visitors can sit in pubs sipping craft beers chill-filtered by 100,000-year-old glacial ice.

    It’s a place to be awed by the UNESCO World Heritage Icefjord where Manhattan skyscraper-sized icebergs disgorge from Greenland’s icecap to float like ghostly ships in the surrounding Disko Bay.

    Small boats take visitors out to sail closely among the bay’s magnificent iceberg flotilla. But not too close.

    “I was on my boat once and saw one of these icebergs split in two. The pieces fell backwards into the sea and created a giant wave,” said David Karlsen, skipper of the pleasure-boat, Katak. “…I didn’t hang around.”

    Disko Bay’s other giants are whales. From June to September breaching humpback whales join the likes of fin and minke whales feasting on plankton. Whale-watching is excellent all around Greenland’s craggy coastline.

    Whales are eaten here. Visitors shouldn’t be surprised to encounter the traditional Greenlandic delicacy of mattak — whale-skin and blubber that when tasted is akin to chewing on rubber. Inuit communities have quotas to not only hunt the likes of narwhals but also polar bears, musk-ox and caribou — which can also appear on menus.

  22. Kevinwak表示:

    A long time in the making
    Curiosity landed in Gale Crater on August 6, 2012. More than 12 years later, the rover has driven over 21 miles (34 kilometers) to ascend Mount Sharp, which is within the crater. The feature’s many layers preserve millions of years of geological history on Mars, showing how it shifted from a wet to a dry environment.
    celer bridge
    Perhaps one of the most valuable samples Curiosity has gathered on its mission to understand whether Mars was ever habitable was collected in May 2013.

    The rover drilled the Cumberland sample from an area within a crater called Yellowknife Bay, which resembled an ancient lake bed. The rocks from Yellowknife Bay so intrigued Curiosity’s science team that it had the rover drive in the opposite direction to collect samples from the area before heading to Mount Sharp.
    Since collecting the Cumberland sample, Curiosity has used SAM to study it in a variety of ways, revealing that Yellowknife Bay was once the site of an ancient lake where clay minerals formed in water. The mudstone created an environment that could concentrate and preserve organic molecules and trapped them inside the fine grains of the sedimentary rock.

    Freissinet helped lead a research team in 2015 that was able to identify organic molecules within the Cumberland sample.

    The instrument detected an abundance of sulfur, which can be used to preserve organic molecules; nitrates, which are essential for plant and animal health on Earth; and methane composed of a type of carbon associated with biological processes on Earth.

    “There is evidence that liquid water existed in Gale Crater for millions of years and probably much longer, which means there was enough time for life-forming chemistry to happen in these crater-lake environments on Mars,” said study coauthor Daniel Glavin, senior scientist for sample return at NASA’s Goddard Space Flight Center in Greenbelt, Maryland, in a statement.

  23. BradyGem表示:

    lisansl? casino siteleri: casino siteleri – slot casino siteleri casinositeleri1st.com

  24. Leonardmooli表示:

    Everyone is talking about Greenland. Here’s what it’s like to visit
    cow fi

    A few months ago, Greenland was quietly getting on with winter, as the territory slid deeper into the darkness that envelops the world’s northerly reaches at this time of year.

    But President Donald Trump’s musings about America taking over this island of 56,000 largely Inuit people, halfway between New York and Moscow, has seen Greenland shaken from its frozen Arctic anonymity.

    Denmark, for whom Greenland is an autonomous crown dependency, has protested it’s not for sale. Officials in Greenland, meanwhile, have sought to assert the territory’s right to independence.

    The conversation continues to intensify. A contentious March 28 visit to a US military installation by Usha Vance, the second lady, accompanied by her husband, Vice President JD Vance, was the latest in a series of events to focus attention on Trump’s ambitions for Greenland.

    The visit was originally planned as a cultural exchange, but was shortened following complaints from Greenland Prime Minister Mute B. Egede.

    Had the Vances prolonged their scheduled brief visit, they would’ve discovered a ruggedly pristine wildernesses steeped in rich Indigenous culture.

    An inhospitable icecap several miles deep covers 80% of Greenland, forcing the Inuit to dwell along the shorelines in brightly painted communities. Here, they spend brutally cold winters hunting seals on ice under the northern lights in near perpetual darkness. Although these days, they can also rely on community stores.

    The problem for travelers over the years has been getting to Greenland via time-consuming indirect flights. That’s changing. Late in 2024, the capital Nuuk opened a long-delayed international airport. From June 2025, United Airlines will be operating a twice-weekly direct service from Newark to Nuuk.

    Two further international airports are due to open by 2026 — Qaqortoq in South Greenland and more significantly in Ilulissat, the island’s only real tourism hotspot.

  25. Johnniebax表示:

    Curiosity rover makes ‘arguably the most exciting organic detection to date on Mars’
    bungee exchange

    The NASA Curiosity rover has detected the largest organic molecules found to date on Mars, opening a window into the red planet’s past. The newly detected compounds suggest complex organic chemistry may have occurred in the planet’s past — the kind necessary for the origin of life, according to new research.

    The organic compounds, which include decane, undecane and dodecane, came to light after the rover analyzed a pulverized 3.7 billion-year-old rock sample using its onboard mini lab called SAM, short for Sample Analysis at Mars.

    Scientists believe the long chains of molecules could be fragments of fatty acids, which are organic molecules that are chemical building blocks of life on Earth and help form cell membranes. But such compounds can also be formed without the presence of life, created when water interacts with minerals in hydrothermal vents.

    The molecules cannot currently be confirmed as evidence of past life on the red planet, but they add to the growing list of compounds that robotic explorers have discovered on Mars in recent years. A study detailing the findings was published Monday in the journal Proceedings of the National Academy of Sciences.
    The detection of the fragile molecules also encourages astrobiologists that if any biosignatures, or past signs of life, ever existed on Mars, they are likely still detectable despite the harsh solar radiation that has bombarded the planet for tens of millions of years.

    “Ancient life, if it happened on Mars, it would have released some complex and fragile molecules,” said lead study author Dr. Caroline Freissinet, research scientist at the French National Centre for Scientific Research in the Laboratory for Atmospheres, Observations, and Space in Guyancourt, France. “And because now we know that Mars can preserve these complex and fragile molecules, it means that we could detect ancient life on Mars.”

發佈回覆給「GarrettMom」的留言 取消回覆

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