I'm working on a project for the iPad where I'm trying to simulate the rotation of a 3D-body with touch by switching pre-rendered images.
I'm not the sharpest man when it comes to memory management so I wonder if anyone has any tips on how to optimize this.
My solution now looks something like this:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [[event allTouches] anyObject];
CGPoint location = [myTouch locationInView:self.view];
int pictureIndex;
//Rough mapping of image to point on screen
if (location.x <= 384 ) {
pictureIndex = (384 - location.x)/(768/rotatingPictures)+1;
}
else {
pictureIndex = rotatingPictures - (location.x-384)/(768/rotatingPictures)+1;
}
[theImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image_%d.png", pictureIndex]]];
}
Is it efficient to load the images this way? Would it be better to load the images to an array first or something like that?
I would prefer to have all loading time at once and not while rotating.