I've been trying to find out for the last 2 days why even after I tell cocos2d to remove textureatlas
it keeps holding memory.
I have no leeks on intruments, I'm debbuging inside CCTextureCache class and it removes just time
I've tried all the obvious ways to remove texture atlas from cache ex: [[CCDirector sharedDirector] purgeCachedData]; with no success
I'm very hopeless, any help?
Edit:
I'm having the same problem than this guy LINK , my game has 1 texture atlas for each level and I repeat the player sprites each image texture atlas files which works great.
my idea was having about up to 30 levels in the game, where it would cost disk space and Assuming I was able to free the memory from the previous texture atlas belonging to the previous level, it would work just fine.
but because I can't find a way to free the memory, the game consumes lots of memory in the 5th level.... it is very frustrating.
any tips are appreciated, thanks
Edit:
I found out what is going on, I have some animations that executed a selector at the end of it. I can't remove those selectors, or if I do, I will have to work a lot. I'm pretty upset because the removeallselectors method just doesnt work
Related
My project runs at 55-60FPS on an iPhone 6 but anything older is completely unplayable because something is eating CPU.
I think the issue is related to the number of tiles and layers on my map (64x256 with 4 layers) and Instruments shows "SKCRenderer:preprocessSpriteImp(..." taking 5198ms (23.2%) running time.
Does JSTileMap load every single tile's image (visible or not) at once? This post from RW indicates that is the case and that it could be worked around for large performance boosts:
http://www.raywenderlich.com/forums/viewtopic.php?f=29&t=9479
In another performance note - Sprite Kit checks all it's nodes and
decides which ones it needs to display each frame. If you have a big
tile map, this can be a big performance hit. JSTileMap loads all the
nodes (SKSpriteNode for each tile) when it loads the tile map. So, I
was also seeing performance issues in the Sprite Kit version with my
maps (which are 500 x 40 tiles). I added a check to my version of
JSTileMap that's included in the kit that marks the hidden property of
each tile, then intelligently unhides and hides only the tiles that
enter/exit the screen space. That increased performance on these
larger maps significantly.
Unfortunately that post does not go into detail regarding the steps taken to remedy this.
My first thought was to (I'm a beginner, please be gentle) create an array of nodes by looping through each point and checking for a tile on the specific layer. From there I'd work on adding/removing them based on distance from the player.
This didn't work, because the process of adding nodes to an array simply caused the app to hang forever on larger maps.
Could someone lend a hand? I'd love to work with larger/more complicated tilemaps but this performance issue is destroying my brain.
Thanks for reading!
UPDATE: Big thanks to SKAToolKit: https://github.com/SpriteKitAlliance/SKAToolKit
Their culling feature solved my problem and I'm now running even larger maps at less than 35% CPU.
JSTileMap has some issues handling larger maps but you do have a couple of options to consider:
Break your large map into several smaller pieces and load each new piece as required.
Only load those objects which are in the player's vicinity.
Only load those tiles which are in the player's vicinity.
I personally found it impossible to accomplish #3 with JSTileMap as I could not locate an array holding the map tiles. I solved this issue by using the SKAToolKit which provides easy access to map tile arrays. It is an excellent resource for parsing maps created in Tiled.
For memory reasons I decided to not use texture atlas anymore, I want to load few sprites from file when I use them.
using batchnode, there was a very handy method which is reorderChild that automatically set sprites to front or back depending the axis they are
Is there any feature like that for free sprites? I'm not asking for the algorithm to do that.. just confirming if there is nothing similar to reorderChild out there before get my hands dirty.
Yes, I searched a lot before coming here,
thanks all
I'm having a performance issue regarding Apple Spritekit Framework.
I use the method preloadTextureAtlases:withCompletionHandler: of SKTextureAtlas to make sure all my textures are loaded before the game really starts.
Yet when the first texture of this atlas (whatever it is) is added to the scene as a child I got a small lag, like if the texture wasn't loaded. It only happens the first time.
I tried real hard to debug this and to find the reason but I couldn't find it. Looking with Instrument and the Time Profiler I got this
Which seems strange since my texture atlas contains all the allocated textures (and they are still allocated). Why does it call a load method ? Maybe it's something related to OpenGL like the texture binding.
I'm sure this correspond to the frame where my object is allocated (see the spike on the right). Nothing else is allocated or in motion here.
I'm really stuck on this and any help would be deeply appreciated.
Thanks for your time.
I am working on a sort of big project. And I have been facing a fatal problem at the end of the day of the project. I guess it might be from memory leak, anyways please listen to my voice.
The first time I launch the program, it works fine. and I play it for about an hour, then when it moves to next scene (this means destroy all things from the memory and load new things on the memory).
I got a error log saying
HeapPool:Init() : can't allocate 33554448 bytes"
Can't Create 2048x2048 texture..
something like that.
After the message, textures are gone. I mean the world (in the game) is black. No textures.
Is this problem related to video memory card? physical memory? or virtual memory? I am not an expert about it.
Anyone can give me an hint? Please, I need anything. Thanks.
It seems you are out of memory, most modern graphics cards can support a 2048 x 2048 texture, anyway, you can check it in DirectX Caps Viewer.
I have seen the usage of plist and png atlasses for the game i am developing. However I've notice a slight performance swiftness(speed up) keeping the 60 fps, and for a side note my app has not crash at the moment.
The thing is I noticed I have used SpriteFrameCache with plist to do CCactions and animations for my characters(sprites). However some of the characters ive been using SpriteBatchnode, but it was on accident, since I am relatively new to deep development of a game, I didnt notice this difference before, they both work, but I feel like both are the same, its just that one has an easier way of implementation than the other, i was thinking that perhaps it was developed in an earlier version....
so my question is. is there a difference between the two? will my game benefit for using SpriteFrameCache over SpriteBatchNode?
Thanks for the help.
FYI: this doesnt slow down my developing, its just a question because I know at the end when my game is finished maybe i would want to optimize performance for my game.
Batch nodes draw all child sprites in one draw call.
Sprite frames hold a reference to a texture and define a region in the texture to draw from. The cache allows you to access sprite frames by name.
Both are different concepts, they are not replacements for each other. You can use sprite frames to create sprites or sprite frame animations. In addition to that sprite batching enables you to speed up rendering of two or more sprites using the same texture.
Note that if you use a batch node with only a single child sprite this will not be any different from rendering the sprite without the batch node, since both create a single draw call so there is no positive effect in using the batch node.