Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-02-2009, 11:37 AM   #1 (permalink)
rusew
New Member
 
Join Date: Jun 2009
Posts: 3
Default Image animation runs slow first time, then fast

Hi, I have an array of images (about 100 320x240px 8k jpgs) that I run through using a timer. The first time the timer cycles through the images it goes very slowly--i'm guessing about 10fps. After that, it will play quickly (maybe up to 100fps).

First, what's going on here? I'm super curious. (some kind of memory or cpu throttling?) Second, I want the animation to run fast the first time. The only fix I've found is to run the animation once with the UIImageView offscreen. This takes a few seconds, however, which adds to the loading time. Is there a better way of "preloading" these images?

Here's my code. I'm on a 3g iphone with 3.0 sdk.

Code:
-(IBAction)startPressed:(id)sender{
	
	NSTimer *timer;
	
	timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
							target: self
							selector:@selector(handleTimer:)
							userInfo: nil
							repeats: YES];
	
}

- (void) handleTimer: (NSTimer *) timer
{	
	static int i = 0;

	if(i > imageArray.count - 1){
		[timer invalidate];
		i=0;
		return;
	}

	finger.image = [imageArray objectAtIndex:i];
        NSLog(@"%d", i);
	i++;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {	
	int i;
	NSString *loadString;
	imageArray = [[NSMutableArray alloc] init];
	
	for(i = 1; i < 100; i++) {
		loadString = [NSString stringWithFormat:@"finger %03d", i]; 	
		[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:loadString ofType:@"jpg"]]];
		NSLog(loadString);
	}
	
	finger.image = [imageArray objectAtIndex:0];
	NSLog(@"Array Count: %d", [imageArray count]);
    [super viewDidLoad];

}
rusew is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,841
Threads: 38,605
Posts: 169,509
Top Poster: smasher (2,547)
Welcome to our newest member, ashim1488
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.