Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-02-2009, 12:37 PM   #1 (permalink)
rusew
Registered Member
 
Join Date: Jun 2009
Posts: 4
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
 

» Advertisements
» Online Users: 716
14 members and 702 guests
ADY, at0m87, Dalia, Don, fgreg2692log, foolshityella, jakerocheleau, Khurshid, PetarPM, PeterBishop, suresk, Touchmint, yufengts
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,632
Threads: 89,149
Posts: 380,345
Top Poster: BrianSlick (7,110)
Welcome to our newest member, foolshityella
Powered by vBadvanced CMPS v3.1.0

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