我已經爲iOS遊戲寫了一個簡單的動畫,並且我試圖將它轉換爲Mac OS。可可的簡單動畫Objective-C
這裏是我的iOS
NSMutableArray *imgArr = [[[NSMutableArray alloc] init] autorelease];
for(int i = 1; i < 6 + 1; i++) {
[imgArr addObject: [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png", filePrefix, i]]];
}
UIImageView * animation = [[UIImageView alloc] initWithFrame:rect];
animation.animationImages = imgArr;
animation.animationRepeatCount = 1;
[animation startAnimating];
[self.view addSubview:animation];
至於可可代碼,這部分給出了錯誤..我怎樣才能解決這個問題?
//animation.animationImages = imgArr;
//animation.animationRepeatCount = 1;
//[animation startAnimating];
與計時器
for(int i = 0; i < 6; i++)
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(anim)
userInfo:nil
repeats:NO];
- (void)anim {
++num;
NSImageView *animation = [[NSImageView alloc] initWithFrame:NSMakeRect(shipPosition.x, shipPosition.y, shipSize.width, shipSize.height)];
[animation setImage: [NSImage imageNamed:[NSString stringWithFormat:@"explosprite%d.png", num]] ];
[objectView addSubview:animation];
[animation release];
}
我剛剛回答了[與本質相同的目標的另一個問題](http://stackoverflow.com/q/14064328/30461)。 (順便說一句,你知道你的代碼創建了一個新的NSImageView的每一幀,並沒有清理舊的,對吧?) –