Hi there!
I'm making a game which requires multiple images to be drawn on the screen. The code I'm using for this is:
- (void)drawRect:(CGRect)rect {
for (i=1;i<=totalImages;i++) {
if (imageExists[i]) {
[image drawAtPoint:CGPointmake(imageX[i],imageY[i])];
}
}
}
This drawRect is called by a function:
-(void) gameLoop {
[self setNeedsDisplay];
}
And the gameloop is called 60 timers per second by a timer:
[NSTimer scheduledTimerWithTimerInterval:0.01666 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
imageExists[], imageX[] and imageY[] are arrays I use in my gamecode to create/remove and move the images across the screen.
My problem is that when I have about 40 images moving around the framespeed is almost halved from when there was only 1 image. And my game will require 88 images max. (this only happens when I test it on my iPod Touch, in the Simulator everything works fine...)
My question is: why is the drawrect function that slow, or is it the drawAtPoint? And how can I fix this? Should I actually use this for drawing images, or should I learn OpenGL ES for making games?