フレームレート(アニメーションの再生速度)は、1秒あたりのフレーム数で表されます。フレームレートが遅過ぎると、アニメーションの動きがぎこちなくなります。早過ぎると、アニメーションの動きに悪影響が出たり、ユーザのコンピュータ処理能力を過剰に消費することがあります。ランタイムを介して、アニメーションのフレームレートを動的に変更することは新しいActionScript 3.0機能の一つです。 この機能で、キーフレームのタイミングを精密に指定しなくても遅いモーションのアニメーションは作成できます。 また、遅いマシンにも、動的にフレームレートを下げたい場合、これを使用すればできます。それでは、やってみましょう。
|
|
はじめに
私は、この新しい機能を紹介するため、簡単な例を作成しました。この例で、単純に矢印ボタンを使用して、アニメーションのフレームレートを増減できます。そのフレームレートの変更でアニメーションへの影響効果はやさしく見えます。
フレームレート60の設定
私がフレームレートの上限を60fpsに設定しました。ブラウザのFlash Playerは60 fpsでキャップアウトするからです。
例
![]() |
アクションスクリプトソース
- [sourcecode language='JavaScript']
- //imports the necessary as events
- import flash.events.MouseEvent;
- //Define the initial stage frame rate
- this.stage.frameRate=1;
- rateTxt.text=”1 fps”;
- //attaching mouse events to the buttons on stage
- arrowUp.addEventListener(MouseEvent.MOUSE_DOWN, arrowPressUp);
- arrowUp.addEventListener(MouseEvent.MOUSE_OUT, arrowOut);
- arrowUp.addEventListener(MouseEvent.MOUSE_OVER, arrowOver);
- arrowDown.addEventListener(MouseEvent.MOUSE_DOWN, arrowPressDown);
- arrowDown.addEventListener(MouseEvent.MOUSE_OUT, arrowOut);
- arrowDown.addEventListener(MouseEvent.MOUSE_OVER, arrowOver);
- function arrowPressUp(event:MouseEvent):void {
- if(this.stage.frameRate < 59)
- {
- //Incrementing the frame rate
- this.stage.frameRate=this.stage.frameRate+1;
- rateTxt.text= (this.stage.frameRate + 1) + " fps";
- }
- }
- function arrowPressDown(event:MouseEvent):void {
- if(this.stage.frameRate > 1)
- {
- //Decrementing the frame rate
- this.stage.frameRate=this.stage.frameRate-1;
- rateTxt.text= (this.stage.frameRate – 1) + ” fps”;
- }
- }
- //On mouse over function
- function arrowOver(event:MouseEvent):void {
- event.target.alpha = 1;
- }
- //On mouse out function
- function arrowOut(event:MouseEvent):void {
- event.target.alpha = .7;
- }
- [/sourcecode]
メインコンテンツEND ■
Posted on Wednesday, 25th November 2009 by admin
Tags: Tutorial
Posted in ActionScript | Comments (0) | 613 views


