2015-05-28 24 views
0

我試着在這裏查看至少半打問題,我似乎無法弄清楚如何正確預加載圖像。第一次運行總是滯後於每個動畫,直到我失去了25%的幀。這不是最引人注目的事情,但它絕對是明顯的。之後,當他們已經加載它不再口吃了。它們是相對較短的動畫,沒有一個超過20個PNG。在xcode的第一次運行動畫口吃

我的圖像陣列是

{ 
    Stickman.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed:@"DAL1.png"], 
           [UIImage imageNamed:@"DAL2.png"], 
           [UIImage imageNamed:@"DAL3.png"], 
           [UIImage imageNamed:@"DAL4.png"], 
           [UIImage imageNamed:@"DAL5.png"], 
           [UIImage imageNamed:@"DAL6.png"], 
           [UIImage imageNamed:@"DAL7.png"], 
           [UIImage imageNamed:@"DAL8.png"], 
           [UIImage imageNamed:@"DAL9.png"], 
           [UIImage imageNamed:@"DAL11.png"], 
           [UIImage imageNamed:@"DAL11.png"], 
           [UIImage imageNamed:@"DAL12.png"], 
           [UIImage imageNamed:@"DAL13.png"], 
           [UIImage imageNamed:@"DAL14.png"], 
           [UIImage imageNamed:@"DAL15.png"], 
           [UIImage imageNamed:@"DAL16.png"], 
           [UIImage imageNamed:@"DAL17.png"], 
           [UIImage imageNamed:@"DAL18.png"], 
           [UIImage imageNamed:@"DAL19.png"], 
           [UIImage imageNamed:@"DAL20.png"], 

           nil]; 
    [Stickman setAnimationRepeatCount:1]; 
    Stickman.animationDuration = 1.52; 
    [Stickman startAnimating]; 
} 

起初我還以爲是模擬器的滯後性,但是當我嘗試過了一個真正的設備上它仍然有同樣的問題。

+0

你能以「播種」的動畫引擎,包括空白圖像的一個動畫解決呢? – matt

+0

另外,如果您在非常短的時間(例如'0.1')GCD延遲中調用'startAnimating',它有什麼區別嗎? – matt

回答

1

1 - 你需要嘗試加載圖像陣列之前startAnimation(應用程序沒有完成,鑑於沒有例如負載)

- (void)viewDidLoad { 
    Stickman.animationImages = @[[UIImage imageNamed:@"DAL1"], 
       [UIImage imageNamed:@"DAL2"], 
       [UIImage imageNamed:@"DAL3"], 
       [UIImage imageNamed:@"DAL4"]]; 
    [Stickman setAnimationRepeatCount:1]; 
    Stickman.animationDuration = 1.52; 
} 

- (void)startYourAnimation { 
    [Stickman startAnimating]; 
} 

2日 - 嘗試使用計時器和自定義動畫類。

- (void)startAnimation { 
    timer = [NSTimer timerWithTimeInterval:0.25f target:self selector:@selector(hideandview) userInfo:nil repeats:NO]; 
} 

- (void)stopAnimation { 
    if (timer != nil) { 
     [timer invalidate]; 
     timer = nil; 
    } 
} 

- (void)nextFrame { 
    frame++; 
    if (frame > frameNumber) { 
     frame = 0; // For cycle 
    } 
    Stickman.image = [UIImage imageNamed:[NSString stringWithFormat:@"DAL%d", frame]]; 
} 

3日 - 優化您的圖像資源(尺寸,擴展) - .JPEG在內存要求不高

+0

我嘗試了一些類似的東西,我在一個動畫中將每個單獨的png放在viewdidload的底部,並讓它在半秒間隔內運行一次。它似乎解決了這個問題。動畫中的定時器需要什麼? –