Skip to main content
Known Participant
February 21, 2012
Answered

CopyPixel large image killing FPS on iOS

  • February 21, 2012
  • 1 reply
  • 1068 views

So, problem is pretty simple (and limited to the iPhone 3GS, the 4+ seems to handle it ok).  I've got a game that uses sprite blitting. So the rendering methods looks something like this:

background.copyPixels(background,rect,point);

then for each sprite :

sprite.copyPixels(spriteSheet,rect,point);

Pretty standard blitting stuff.  The problem is when I blit the background image (which is one large 960x640 image) the iPhone justs chokes. Cuts my FPS in half. 

For an experiment I tried using fillRect to just clear the bitmap between each frame instead of recopying the BG image, and fillRect took just as long (13FPS!).

Obviously the iPhone 3GS is choking on blitting such a large image.  Anyone got anythoughts on how to optimize this?  I'd much rather fix it then have to drop all those devices. 

thanks guys

This topic has been closed for replies.
Correct answer Colin Holgate

That sounds like a good solution, I'm not sure I know the process to 'resize' the blit to a lower resolution. I thought it was always a 1 to1 situation with copyPixel. Though, I've always been more of an artist than a programmer- so by all means feel free to educate me!


You could put the png that is the sprite sheet into a movieclip that is set to 50% size, then use the draw() function to draw it into a new bitmapdata object, which you then blit from.

1 reply

Known Participant
February 21, 2012

UPDATE:

I wrote up a quick test to try 'damage mapping' see explination here: http://www.8bitrocket.com/2009/05/03/tutorial-clearing-a-blit-canvas-by-erasing-only-the-portions-that-have-changed-using-damage-maps-or-a-dirty-rect/

basically only blitting the bitmap where the sprites are as opposed to the entire thing.

Yes, it is faster than copying the whole bg everyframe. Unfortunately, as soon as the number of sprites on screen increases to a decent level- its still having to proccess almost just as information as copying the entire back ground.  And the FPS drops right back down.

I'm guess I'm boned here as far as the 3GS support.  Which is unfortuante, as I'm sure that accounts for about 20 or 30 million devices.  I'm also guessing that if all my assets were based on 480x320 instead of 960x640 I wouldn't have this issue.  Anyone know of a quick and easy way to downrez all my bitmaps by x2?

I'm not sure if I can make seperat builds for 3GS and 4 (a low rez and a high rez)  maybe one more knowledgeable than I can help me out there. 

-dis

Colin Holgate
Inspiring
February 21, 2012

Could you, on start up, copy your sprite sheets into a bitmap that is a quarter of the size? Then do the blitting on the 3gs as 480x320. You ought to get four times the frame rate.

Known Participant
February 21, 2012

That sounds like a good solution, I'm not sure I know the process to 'resize' the blit to a lower resolution. I thought it was always a 1 to1 situation with copyPixel. Though, I've always been more of an artist than a programmer- so by all means feel free to educate me!