CCSpriteBatchNode changes opacity of frame - Cocos2d - iphone

When I add a sprite to my scene from
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
#"b.plist"];
bspriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"b.png"];
[self addChild:bspriteSheet z:-1];
the opacity of the sprite is lighter than it was originally and the images look fine in "b.png". Does anyone know why it is doing this and is there a way to fix it?

Possibly because it's z-index is behind another view which is then somehow masking it. Try changing the z-index to 0 or 1 and see if that works.

Related

Change CCSprite images at runtime

need to change the CCSprite images at runtime, i have to delete the previous loaded images and display new after a specific inter of NSTimer, i am using [imagesContainer removeChildByTag:0 cleanup:YES]; but not working
any help will be highly appreciated
You could remove the sprite like you're doing and add a new sprite but remember to add it to the layer with addChild:
CCSprite *theNewSprite = [CCSprite spriteWithFile:#"newImage.png"];
[LayerYouWantToAdd addChild:theNewSprite]
Or just change the texture of the sprite. This works for me.
[theSprite setTexture:[[CCSprite spriteWithFile:#"newImage.png"]texture]];

Transparent layer used in Tiny wings

please can anyone show me how to implement using cocos2d, a half transparent layer that is tapped for game start like that obtained in the game called Tiny wings.
Thanks.
Add a CCSprite to the scene then set the opacity to something less than 255 to make it translucent.
Here is some psuedo-code:
CCSprite* myTranslucentImage = [CCSprite spriteWithFile:#"touchMe.png"];
myTranslucentImage.opacity = 128;
[scene addChild: myTranslucentImage];
I've never played Tiny Wings but I do know how to make a CCSprite transparent.
CCSprite *example = [CCSprite spriteWithImage:#"HelloWorld.png"];
[example setOpacity:160];
If you must use a CCLayer you should look at the Cocos2d documentation.

How to add transition effect in Current running scene in cocos2d iphone

How to add transition effect in Current running scene in cocos2d iphone. Means I am making a game and after each goal I want to give a fade effect or any type of effect on the current running scene.
If I write this, It replace current scene to its new scene. But I don't want to replace scene.
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0f scene:[GamePage scene]]];
Is there some way to show effect on the current page like this. I know that it is wrong but I want something like this :
[self transitionEffect:[CCTransitionFade actionWithDuration:0.5]];
For Scene,Layer (Subclass of CCNode) action related to Opacity will not work. !
You can Either Use transition, or Must have to apply CCFadeTo to all of your sprite.
But If you are choosing to CCFadeTo to all sprites, this will require allocation of lots of actions suddenly ! FPS slow down !!
Another best approach:
Tell to your designer, to make 1 x 1 pixel Square black dot image.
Add this code at last in the init method.
CCSprite *temp=[CCSprite spriteWithFile:#"squaredotBlack.png"];
temp.position=ccp(s.w/2,s.h/2);
[self addChild:temp z:50000]; //set as most top layer
temp.scaleX=s.w;
temp.scaleY=s.h;
temp.opacity=0;
Then Apply, For "Fade out" process of whole screen, Increase the opacity.
temp.opacity=0;
[temp runAction:[CCFadeTo actionWithDuration:1 opacity:255]]; //0 to 255
Then Apply, For "Fade In" process of whole screen, decrease the opacity.
temp.opacity=255; // this will cover whole screen with black color
[temp runAction:[CCFadeTo actionWithDuration:1 opacity:0]]; //255 to 0
you can run an action on the entire CCLayer
[self runAction:[CCFadeOut actionWithDuration:0.5f]];
or you can use CCFadeTo to fade to a desired opacity.

PNG Transparency in cocos2d iphone issue

I've just begun cocos2d development on the iphone. An issue I'm having is that when I add a CCSprite to my scene, instead of it being transparent around the edges of the .png file, its showing up as white.
So for example, I define the CCSprite in my header file -
CCSprite *foo;
Then when I initialise my scene -
foo = [CCSprite spriteWithFile:#"foo.png"];
[self addChild:player z:0 tag:1];
Is there anything wrong with this code?
Thanks for any help.
P.S. I have double checked my .png file in Photoshop and its correctly showing up as transparent where it should be.
Check the bottom portion of this page:
http://www.cocos2d-iphone.org/wiki/doku.php/faq#my_png_doesn_t_look_like_in_photoshop

add animation in cocos2d

how can I add animation in cocos2d in a sprite, the problem is that whenever the use fire the object and hits that object, the object will remove just like an animation .. if you have any tutorial then plz send it to me...
thnx
You can use spritesheets of images and then do animation using the images.
For code examples you can try the following tutorial.
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d
There are a lot of examples coming with cocos2d. Including animation using a set of images. Take a look at SpriteTest example - it's what you are looking for
just use this
CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:#"yourImage.png" capacity:5];
[self addChild:mgr z:0 tag:4]; //set the image and load it to the CCLayer
sprite = [CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(0, 0, 30, 30)];
[sprite runAction:[CCFadeTo actionWithDuration: 1 opacity:80]];