フレームレート(アニメーションの再生速度)は、1秒あたりのフレーム数で表されます。フレームレートが遅過ぎると、アニメーションの動きがぎこちなくなります。早過ぎると、アニメーションの動きに悪影響が出たり、ユーザのコンピュータ処理能力を過剰に消費することがあります。ランタイムを介して、アニメーションのフレームレートを動的に変更することは新しいActionScript 3.0機能の一つです。 この機能で、キーフレームのタイミングを精密に指定しなくても遅いモーションのアニメーションは作成できます。 また、遅いマシンにも、動的にフレームレートを下げたい場合、これを使用すればできます。それでは、やってみましょう。

DoNotYet Dynamically Adjust the Frame Rate of a Flash Animation frames-per-second

はじめに

私は、この新しい機能を紹介するため、簡単な例を作成しました。この例で、単純に矢印ボタンを使用して、アニメーションのフレームレートを増減できます。そのフレームレートの変更でアニメーションへの影響効果はやさしく見えます。

 

フレームレート60の設定

私がフレームレートの上限を60fpsに設定しました。ブラウザのFlash Playerは60 fpsでキャップアウトするからです。

 

DoNotYet Dynamically Adjust the Frame Rate of a Flash Animation change-frame-rate-example

 

アクションスクリプトソース

  1. [sourcecode language='JavaScript']
  2. //imports the necessary as events
  3. import flash.events.MouseEvent;
  4. //Define the initial stage frame rate
  5. this.stage.frameRate=1;
  6. rateTxt.text=”1 fps”;
  7.  
  8. //attaching mouse events to the buttons on stage
  9. arrowUp.addEventListener(MouseEvent.MOUSE_DOWN, arrowPressUp);
  10. arrowUp.addEventListener(MouseEvent.MOUSE_OUT, arrowOut);
  11. arrowUp.addEventListener(MouseEvent.MOUSE_OVER, arrowOver);
  12.  
  13. arrowDown.addEventListener(MouseEvent.MOUSE_DOWN, arrowPressDown);
  14. arrowDown.addEventListener(MouseEvent.MOUSE_OUT, arrowOut);
  15. arrowDown.addEventListener(MouseEvent.MOUSE_OVER, arrowOver);
  16.  
  17. function arrowPressUp(event:MouseEvent):void {
  18. if(this.stage.frameRate < 59)
  19. {
  20.  //Incrementing the frame rate
  21. this.stage.frameRate=this.stage.frameRate+1;
  22. rateTxt.text= (this.stage.frameRate + 1) + " fps";
  23. }
  24. }
  25. function arrowPressDown(event:MouseEvent):void {
  26. if(this.stage.frameRate > 1)
  27. {
  28. //Decrementing the frame rate
  29. this.stage.frameRate=this.stage.frameRate-1;
  30. rateTxt.text= (this.stage.frameRate1) + ” fps”;
  31. }
  32. }
  33.  
  34. //On mouse over function
  35. function arrowOver(event:MouseEvent):void {
  36. event.target.alpha = 1;
  37. }
  38.  
  39. //On mouse out function
  40. function arrowOut(event:MouseEvent):void {
  41. event.target.alpha = .7;
  42. }
  43. [/sourcecode]
メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Wednesday, 25th November 2009 by admin

Tags:
Posted in ActionScript | Comments (0) | 613 views

Leave a Reply