Maximum number of sprites?

I’m loading multiple spritesheets, and this year, I’m trying to load a lot more layers to support jersey numbers. However, I’m not seeing all the sprites loaded, and I I shifted the order to check if it was a problem in the images, but that’s not it. It seems that I’m hitting some sort of limit?

Is there a limit with the number of sprites or perhaps I’m hitting a memory limit?

I can’t figure a good solution for this without loading 22 sheets of jersey numbers to overlay the players. :frowning:

thanks!

I think your problem is the sprites can not be loaded completely in Cocos Game.

  1. There i no memory limit in Cocos.
  2. If sprites can not be loaded, could you please provide the error log for me?Or they can not trigger the load call back function?

Thanks for replying. It’s very bizarre, and the behavior is inconsistent. At one point yesterday, I was loading 20 sheets, but immediately after, I fell back to where I can load only 10, even after a game restart. I don’t think I’m failing to remove any frames from the cache.

I’m not getting any errors, it simply doesn’t show a sprite. In fact, the sprite that I pull from the cache isn’t null, but nothing shows up. However, at some point, when I’m adding sheets, I notice that the size of the cache stops growing.

I use SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
to load each sheet, and I added this code to that method:

CCLOG("before, _spriteFrames size = %d, _loadedFileNames size = %d",
      _spriteFrames.size(), _loadedFileNames->size());

I also call removeSpriteFramesWithFile() before calling the add method. Is removeSpriteFramesWithFile() synchronous? I’ve been assuming it is.

I don’t have any callbacks.

Later, when I want the sprites, I call
jerseySprite = Sprite::createWithSpriteFrameName(jerseyName);

Right now, I’m wondering if maybe I’m doing something wrong. Say I have this:

  • plist named my_image.plist
  • png named my_image.png

In the plist, what should the textureFileName be? I’ve tried setting it to my_image.plist and to my_image.png, and even tried just leaving it out.

I got it to work by cutting the spritesheets down 50% in each direction. They still look just as good, so I think I was hitting some memory threshold.

You can check the memory limit of your app in android app through the method below:

    private void getMaxMemoryInfo(){
        Runtime rt = Runtime.getRuntime();
        long maxMemory = rt.maxMemory();
        Log.e("MaxMemory:", Long.toString(maxMemory/(1024*1024)));
        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        Log.e("MemoryClass:", Long.toString(activityManager.getMemoryClass()));
        Log.e("LargeMemoryClass:", Long.toString(activityManager.getLargeMemoryClass()));
    }

Also you can check left memory, low memory and threshold status through the method below.

private void getMemoryInfo() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
    manager.getMemoryInfo(info);  
    Log.e("Memory","total mem:"+(info.totalMem / (1024*1024))+"M");
    Log.e("Memory","left mem:"+(info.availMem / (1024*1024))+"M");
    Log.e("Memory","in low mem:"+info.lowMemory );
    Log.e("Memory","threshold mem"+( info.threshold  / (1024*1024)));
}

Thanks! I’ll try this this weekend. Thanks a ton!