tobyc
tobyc

Reputation: 2237

Loading only visible areas of a large image in cocos2d

We're using cocos2d to display a large image which is comprised of three different parallaxing layers within an app for iPhone/iPad. The user will be able to pan around this large image.

These images will be approximately 13000 pixels wide, so we're concerned about memory usage. Ideally we'd like to grid the image up and load subsections of it based on what is currently visible.

Does cocos2d include anything that will help us with this? We've looked at using Tile maps (we have a prototype running on CCTMXTiledMap), but it doesn't seem like this is actually a good application of tile maps, as they're generally used for large maps/images that are comprised of repeated smaller images; whereas every tile in our large images will be unique.

Does anyone have any bright ideas about the best way to do this?

Upvotes: 0

Views: 402

Answers (1)

TigerCoding
TigerCoding

Reputation: 8720

I remember seeing a post on a blog where an iPhone programmer has images loading on a background thread as the screen scrolled. He said so long as the scrolling isn't too fast, it's not a problem to achieve smooth scrolling.

You basically load the sections of the images based on where the screen is scrolling toward, and deallocate the images that leave the screen border. So there would be the screen itself, and a border around the edges of the screen to act as a buffer in case the player goes back and forth (left or right, etc).

I wish I could find the link, but after searching for 30 minutes I gave up. I did see his video and it scrolled very smoothly.

Upvotes: 1

Related Questions