Hi, I have made a menu screen that uses different layers for each section of the menu. However, I have noticed bad performance for the menu so I wanted to start using Atlas Sprites. However I cant seem to figure out a way to share a CCSpritesheet between different layers in the same scene. I am using 0.99. Any help I could get here would be appreciated.
Share a Spritesheet between layers.
(8 posts) (4 voices)-
Posted 1 year ago #
-
If all the menu Layers are children of the same parent Scene, you can add the CCSpriteSheet in the parent Scene with a tag and then get a reference to it in the child Layer with something like
(CCSpriteSheet *) ss = [self.parent getChildByTag:theSceneSpriteSheetTag];
and go from there.hth,
Derek.Posted 1 year ago # -
How do you tag something? Also will this let me move my layers and still have the Atlas Sprites of those layers move as expected (with the layer).
Posted 1 year ago # -
I have the same request, I want to use multiple layers to make moving and animating groups of sprites easier. But at the same time I don't want to have multiple (duplicated) sprite sheets.
All attempts so far using references and pointers to the original spritesheet will fail with:
*** Assertion failure in -[CCLayer addChild:z:tag:]when I try to add the spritesheet (primarily a child node of the main scene) to my new layer. It seems that spritesheets can only be a child of one node alone. Is this true? I hope there is a workaround as I want to work in layers (groups) and at the same time only reference one spritesheet.
Any ideas?
Posted 1 year ago # -
If you reference the same sprite sheet from multiple sprite managers, only a single copy of that image will be loaded and cached for the others to share.
At the cost of some extra draw calls per sprite manager, I'd say that's a far easier way to achieve what you want. Is there a particular reason you don't want multiple managers?
In Forest Folk the background is made up of about 6 sprite managers using the same image to get the parallax effect. and the characters are made up of 6 managers each currently! (due to the sheer number of animation frames and a z ordering issue). That still runs at an average of 30fps with box2d running along side. I'm now just going through & optimizing to reduce the number of managers (characters now only have 3 in the latest dev version), but the point is I didn't worry about it until I needed to get some extra fps back out the game.
Posted 1 year ago # -
I was presuming there would be a memory overhead. I'll use a spritesheet for each layer then! I had hoped there was a simple explanation as it seemed rather limiting for otherwise.
Thanks for dispelling my fears.
I've just jumped back into Cocos2d since my early trials with it last year. I have gone from native API UIViews to Unity3d and back to Cocos2d - the OpenGL ES speed is really the main attraction. I have had issues with UIView performance (my project with multiple, large images don't move smoothly enough for my liking) and Unity3d - though I love it's development environment - takes way too long to startup on the iPhone - about 12-15 seconds in my last project.
Posted 1 year ago # -
I figured out a way that works. Have a method on your scene that returns the spritesheet. Add the spritesheet to your scene. Get the spritesheet in each layer and add sprites to the spritesheet. DO NOT ADD THE SPRITE SHEET TO THE LAYER. Then have a method like this in each layer with every one of your atlas sprites in it.
CGPoint current; -(void)setPosition:(CGPoint)p { float x = p.x-current1.x; float y = p.y-current1.y; back1.position =ccp(back1.position.x+x, back1.position.y+y); logo1.position =ccp(logo1.position.x+x, logo1.position.y+y); position_ = p; isTransformDirty_ = isInverseDirty_ = YES; current1 = p; }Posted 1 year ago # -
@babelchips: I looked into Unity before finding cocos2d, and was pretty tempted. But for 2d, it seemed overkill, and I feel I've learnt (& am still learning) a lot by using cocos2d :)
@randomtruth: glad you got dbolli's suggestion to work! One possible issue with doing it that way is mixing z levels with other managers might get a little complex. That was one of the reasons I opted for multiple managers, but for alot of games that shouldn't be a problem, so should work great.
Posted 1 year ago #
Reply
You must log in to post.