cocos2d and lots of spritesheets

Moderator
Posts: 508
Joined: 2002.09
Post: #1
Hey all,

I'm currently stuck with a project that runs fine on the Simulator but not on the iPad. The problem, as you may already have guessed, is it consumes too much memory which crashes de app when run on the iPad.

Now, for this app, I use a lot of spritesheets for a character and they are a quite big. Each character has about 3 types of animation but each type uses at least 2 spritesheets.

Do you guys have any ideas on how I can optimize this and make sure my app doesn't use that much memory? I've tried compressing the spritesheets, it helps a bit but the app will crash eventually.
I'm pretty sure I don't have memory leaks, just warnings but there's not much I can release at that time.

As always, thanks in advance.

BTW: I'm using Cocos2d, the latest version as of this writing.

"When you dream, there are no rules..."
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
What I did was use pvrtc for the "in-between" frames. For instance, if you had a character running, the running frames would be pvrtc, but the standing frames would be regular uncompressed textures. You can save a huge boatload of space this way for frame animated sprites. The pvr compression is awful for the edges of sprites where the transparency starts though, which is why you can't use it for the frames the gamer will see. The "in-between" frames flip by so quickly that they won't notice -- heck, I can't tell and I know they're there!

A drawback, of course, is the extra texture binds required, but that's the price to pay I suppose.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #3
So PVRTC images are the answer basically? I'll give it a try. Thanks man!

"When you dream, there are no rules..."
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.06
Post: #4
No PVRTC is not the answer for sprite sheets. PVRTC is lossy compression, like JPEG. What you need for sprite sheets is lossless compression, because lossy compression will blur your character edges significantly. Also, your sprite sheets will typically need full alpha channel support, or at least a 1 bit alpha channel. If you have lots of frames and a number of character animations, you will basically need to limit allocated memory on your iOS device so that your code will not crash when run on the actual device. I have implemented a library that deals with these specific issues, you can download the source by doing a quick google search on "iOS AVAnimator". My library is not related to Cocos2D, you could use it instead of Cocos2D though. This problem is not easy to solve in general, if you want to tackle it yourself, then you should try to limit the actual allocated memory used by the images as much as possible. Any time an animation series is not being used, it should be deallocated.
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #5
(Jun 9, 2011 02:27 PM)mdejong1024 Wrote:  No PVRTC is not the answer for sprite sheets. PVRTC is lossy compression, like JPEG. What you need for sprite sheets is lossless compression, because lossy compression will blur your character edges significantly.

AnotherJake specifically pointed out the comprises that come along with PVRTC and how to mitigate the artifacts. I know you're trying to pimp your animation tool but from what I gathered on your web page it just doesn't seem like a viable solution for OpenGL texture animation. It does appear to be over-engineered and expensive however.
Quote this message in a reply
Post Reply