Proper implementation of Particle Designer plist emitters in cocos2d? - cocos2d-iphone

I'm confused about how to properly use emitters made in Particle Designer with Retina displays in cocos2d. I have tried using an emitter with a non-hd texture (fire.png for example) saved as "particle.plist" with and without the texture embedded and I get a warning of some kind either way. I then made another emitter with fire-hd.png and the name "particle-hd.plist", and I get the same types of warnings, stuff like, cocos2d: Filename(fire-hd.png) contains -hd suffix. Removing it. See cocos2d issue #1040
Searching for issue #1040 yields a little info, but not enough for me to fix this.
A little enlightenment?

You need to prepare these files.
particle.plist (it uses texture 'fire.png' with or without the texture embedded)
fire-hd.png
CCParticleSystem searches -hd texture file first, then non-hd texture file, and then embedded texture data.
hd / retina partcle systems
EDIT
"Warning HD file not found" for Particle plist is false warning. You can use CCParticleSystem initWithDictionary method without any warning in this case.
NSString *path = [[NSBundle mainBundle]
pathForResource:#"particle1_traile" ofType:#"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
CCParticleSystem *particle = [[[CCParticleSystemQuad alloc]
initWithDictionary:dict] autorelease];

Related

Strange artefacts appear on CCSprite

I have a CCLayer class imported onto a game layer
strangely all the the sprites have "artefacts" that seem to appear from nowhere since I have checked and re-exported all of the files
Is some setting or something else that could cause this to happen?
I'm new at this
but I have checked so far:
set to PixelFormat_RGBA8888
PVRImagesHavePremultipliedAlpha:YES
png's are clear from artefact (28bit with transparency)
Textures are made with texture packer with "pre-multiplied"
The Background is a CCLayer
The Mine is a CCLayer
both are added to the game layer (cclayer also) as "addChild"
backgroundManager = [[BackGround alloc] init];
[self addChild:backgroundManager z:0];
myShip = [[Ship alloc]init];
[self addChild:myShip z:5];
Yes it was the settings in texture packer
after a few changes in the settings they now seem to load fine.
with no artifacts
use pre multiple
trim not crop
and give a little more inner padding
hope it helps someone else (since it was driving me a little crazy)

adding a normal CCSprite to CCSpriteBatchNode crashes

I am getting this exception in logs
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id'
What I am trying to do is adding a normal "myfile.png" file to a SpriteBatchNode
**declaration of batch node
CCSpriteBatchNode *_backgroundLayer = [CCSpriteBatchNode batchNodeWithFile:#"sprites.png"];
** usage
This line works perfect
CCSprite *sprite1 = [CCSprite spriteWithSpriteFrameName:#"PngFileKeptInSpriteSheet.png"];
[_backgroundLayer addChild:sprite1];
But, when I use a direct *.png file to add to batch node, It crashes
CCSprite *sprite2 = [CCSprite spriteWithFile:#"myfile.png"];
crashes on line
[_backgroundLayer addChild:sprite2];
On further debugging I found that:
The assertion failure is in file CCSpriteBatchNode.m
inside method -(void) addChild:(CCSprite*)child z:(NSInteger)z tag:(NSInteger) aTag
at line NSAssert( child.texture.name == textureAtlas_.texture.name, #"CCSprite is not using the same texture id");
P.S. : by "normal" I mean not taken from *.plist file
First and foremost, I'd update cocos2D. However, that isn't your problem and probably isn't "fixed" in the latest version anyway. This isn't really a bug
Batch nodes require that all the sprites that you intend to batch are using the same texture. When you load a sprite sheet, it uses one, large texture. When you call spriteWithFile, cocos2d creates a texture from that image.
It's rare that you'll want to create a batch node from a sprite using spriteWithFile. The only scenario I can think of is when you want to draw the same image many times. (Rather than many images from the same texture).
In short, what you are trying to do is unsupported and doesn't make much sense anyway as the two sprites wouldn't be batchable.

Error adding sprites using addchild method: argument must to be non-nil

I've a problem using the method addchild adding sprites
previously I've never had this problem and I could add png files without problems,now sometimes if I try to add some sprites to the scene using the addchild method I receive these errors:
[2126:15503] cocos2d: CCTexture2D. Can't create Texture. cgImage is nil
[2126:15503] cocos2d: Couldn't add image:image_1.png in CCTextureCache
[2126:15503] * Assertion failure in -[HelloWorldLayer addChild:]
I think that the problem isn't in the code because if I try to add sprites using the images included in the default Cocos2d project it works... I receive this error only from some images...also if I've added it by the same way to the project and to the scene, what could be the cause?
I receive this error also using the default helloWorldLayer class, without changing anything, only adding
CCSprite * sprite = [CCSprite SpriteWithFile: #"image_1.png"];
[self addChild:sprite];
the rest of the code is exactly the same of the default HelloWorldLayer class
there could be something that might cause this error in some png files?
Add image_1.png to your Xcode project. Make sure you use the exact same filename, for example Image_1.PNG won't load on devices due to uppercasing.

reveal the contents of a layer through a rectangle "cut-out" with cocos2d?

I am looking for a way to mask out a layer and reveal the contents of the layer through a rectangle (actually I want multiple rectangles to reveal the underlying layer's content).
I came across this similar question:
Cocos2d iPhone - Sprite cliping/mask/frame
Which had a solution:
http://www.learn-cocos2d.com/2011/01/cocos2d-gem-clippingnode/
However, when trying to use this class, I get the warning: "implicit declaration of function 'glPushMatrix' is invalid in C99"... I also get the error: "Property 'deviceOrientation' not found on object of type 'CCDirector *'"
What do I need to do to get this to work with the latest version of cocos2d?
... In any event, I commented out the deviceOrientation stuff, just to test if it will even work, and it doesn't seem to be.
I've got a CCBatchNode:
sheet = [CCSpriteBatchNode batchNodeWithFile:#"bg.png" capacity:500];
Then I add many sprites to that
[sheet addChild:sprite1];
[sheet addChild:sprite2];
[sheet addChild:sprite3];
Then I make the clipping node layer
ClippingNode *clipNode = [ClippingNode node];
clipNode.clippingRegion = CGRectMake(50, 50, 200, 200);
Then I add the sprite sheet and the clipNode:
[layer addChild:sheet];
[layer addChild:clipNode];
Then I add that to the CCSprite object
[self addChild:layer];
...
The result is, I see my many sprites from the sheet, but there is no clipping mask.. And my console shows a million: "OpenGL error 0x0502 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556"
so..... I am not sure what I am doing wrong-- or if this all has to do with the openGL warnings and device orientation errors... ?
UPDATE: I added #include <OpenGLES/ES1/gl.h> to the ClippingNode.m, and it got rid of the glpush/pop warnings.. But still results in the same OpenGL error once I add the clipNode child to the layer...
You can do it with shaders in cocos2d 2.0. Have a look at this tutorial.
http://www.raywenderlich.com/4428/how-to-mask-a-sprite-with-cocos2d-2-0

Using Zwoptex with Cocos2d's CCSpriteBatchNode on Retina Display

I used the Zwoptex Flash version to generate:
A .png texture file with -hd suffix (double sized images)
A .png texture file without -hd suffix (normal sized images)
A .plist file with -hd suffix.
A .plist file with -hd suffix.
I have checked the files and everything seems to be there alright.
In my game, first I added the .plist file to the cache:
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:#"ParticleAnimations.plist"];
And then I created my CCSpriteBatchNode:
spriteBatch = [CCSpriteBatchNode batchNodeWithFile:#"ParticleAnimations.png"];
[self addChild:spriteBatch z:0];
And finally create my CCSprite, with the filename of an image found in my textures:
CCSprite *particle = [CCSprite spriteWithSpriteFrameName:#"Particle1.png"];
[spriteBatch addChild:particle z:0];
Now, I run this on the simulator (iPhone), and it runs just fine.
Then, I change the Hardware option and set it to "iPhone (retina)", which transforms the simulator on a 960x640 screen. But then, my gane crashes. Within the log, here are these entries:
cocos2d: CCSpriteFrameCache: Trying to use file 'ParticleAnimations.png' as texture
cocos2d: CCSpriteFrameCache: Frame 'Particle1.png' not found
Which I don't quite understand. First of all, why is it using ParticleAnimations.png instead of ParticleAnimations-hd.png, since it is in Retina Display mode? And, of course, why is it looking for Particle1.png instead of Particle1-hd.png?
To begin have you think to uncomment these lines into you appdelegate:
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
It'll enable Cocos2d to use the -hd files.
Then your sprite names must be exacty the same into your spritesheets. Just the plist and texture files must have the "-hd" suffix. For example if you have sprites named toto.png, titi.png, tata.png into your spritesheets named mysp it should look like that:
// Normal
- mysp.png
- mysp.plist
|- toto.png
|- titi.png
|- tata.png
// Retina
- mysp-hd.png
- mysp-hd.plist
|- toto.png
|- titi.png
|- tata.png
For more information, you should refer to the official documentation here: RetinaDisplay in cocos2d
I hope it'll help you!