2012-08-14 22 views
0

我有一個onEnterFrame事件:我需要多少圖片纔能有更流利的動畫(Actionscript);

package { 
    import flash.display.MovieClip; 
    import flash.display.Loader; 
    import flash.events.Event; 
    import flash.net.URLRequest; 
    import flash.display.BitmapData; 
    import flash.geom.Matrix; 
    import flash.errors.IOError; 

    public class Ball extends MovieClip { 

     private var images:Array; 
     private var frames:Array; 
     var i:int = 0; 
     public function Ball(images:Array) { 

      this.images = images 
      frames = new Array(); 
      images.forEach(function(current){ 
         trace(current); 
       var loader:Loader = new Loader(); 
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleted); 
       loader.load(new URLRequest(current)); 
      }); 

     } 

     private function onLoadCompleted(e:Event):void{ 
      frames.push(e.currentTarget.content); 
      i++; 
      if(i == images.length) 
      { 
       ready(); 
      } 

     } 

     private function ready():void{ 

      i = 0; 
      addEventListener(Event.ENTER_FRAME, onEnterFrame); 

     } 

     private function onEnterFrame(e:Event):void{ 


      graphics.clear(); 
      var bitmapData:BitmapData = frames[i].bitmapData; 
      graphics.beginBitmapFill(bitmapData, new Matrix(), false, true); 
      graphics.drawRect(0, 0, 100, 100); 
      graphics.endFill(); 
      i++; 
      if(i == frames.length) 
      { 
       i = 0; 

      } 


     } 

    } 

} 

這個類是獲取圖像的數組,然後蓬勃生機,這是我的主類:

public class Test extends MovieClip { 

     private var ball:Ball; 
     public function Test() 
     { 
      var images:Array = new Array(); 
      for(var i:int = 1; i < 21; i++) 
      { 
       images.push('ball' + i.toString(10) + '.png'); 

      } 
      ball = new Ball(images); 
      addChild(ball); 
     } 

    } 

所以你看我傳遞一個20個圖像的陣列,所以問題是我需要多少圖像才能製作出一個好的動畫,而不是粗略地但順利地創建每個新圖像,例如ball1.png,ball2.png,ball3.png,ball4.png - I需要通過像素移動球像素來製作一個好的動畫?還是有更好的方法來做到這一點?

回答

0

這取決於您的感知和設備以及您想要從內容中形象化的內容。 請參閱本網站

http://www.mathworks.com/help/toolbox/mupad/plot/INTRO_FramesAndTimeRange.html

+0

或什麼是更好的使用顯卡內置對象和他的功能還是通過創建圖像?我是新來的,我不知道如何做得更好,繪製圓圈和線條,我將不得不製作graphics.clear(),並且在每個方法中複製/粘貼代碼以繪製越來越多的某個人或火柴人的動作)或創建30-50圖像)) – 2012-08-14 07:38:34

+0

有很多閱讀=),你能給我一個小問題嗎?) – 2012-08-14 07:53:14

+0

它是一個項目的工作? – sam 2012-08-14 09:22:00

0

我會考慮的第一件事是幀率。將更多圖像作爲幀率沒有意義。

基本上對於一個平滑的動畫30 fps應該沒問題。另外,如果你考慮這個移動設備,我認爲你不應該高於30fps,以獲得良好的性能。

關於圖像的數量,以及如何設置它們的動畫,我建議你看看這個遊戲教程(飢餓的英雄)

http://www.hsharma.com/tutorials/starting-with-starling-ep-3-sprite-sheets/ http://www.hsharma.com/tutorials/starting-with-starling-ep-5-parallax-background/

相關問題