Drawing clouds like shapes in cocos2D - cocos2d-iphone

Im new to cocos2D
I would like to draw cloud like particles similar to the one in the attached figure as one drags across the screen. I tried using CCParticleSmoke but I couldn't control the spreading of the particle. Initialization:
smoke = [[CCParticleSmoke alloc] initWithTotalParticles:100];
smoke.texture = [[CCTextureCache sharedTextureCache] addImage:#"cloud.png"];
smoke.gravity = CGPointZero;
smoke.startColor = _color;
smoke.posVar = CGPointZero;
In gesture method
smoke.position = pointPosition;
[smoke visit];
When I run my code, what happens is perpendicular cloud like particles appear though I dragged parallel. Cant get any clues about what to do.
I don't want particles to spread, but as in the below image. Any timely help is appreciated.
Thanks.

Related

Side scrolling game background

I am working in Cocos2d and xcode to create a side scrolling game.
I have an issue with my coding for adding a background to the levelscene.
I tried to implement a parallax background to no avail so have opted to just have a background the player will scroll across.
But at the moment the background follows the player across the screen, which frankly looks rubbish.
The code I have is
(void)setupParallax {
NSString *backgroundName = [self.tilemap propertyNamed:#"BackgroundImage"];
CCSprite *background = [CCSprite spriteWithFile:[AssetHelper getDeviceSpecificFileNameFor:[NSString stringWithFormat:#"background-noon.png]]];
background.anchorPoint = ccp(0,0);
background.position = CGPointMake(0, 0);
[self addChild:background z:0];
}
I know it must be something with either the position or anchorPoint but these values only change with reference to the screen they are loaded on.
Have you looked at this tutorial on doing parallax scrolling in cocos2d-x?
You an do parallax scrolling by hand...but it will probably easier, at least if you are just starting out, to do it using the CCParallaxNode and let the framework do the heavy lifting for you.

CCParallaxNode adding childs while scrolling

I'am using a CCParallaxNode to scroll 3 backgrounds along with Ray Wenderlich's category to move the backgrounds when they go out of the screen.
It is working just fine, my problem is that i want to add childs (enimies) on the fly, like every 5 seconds. Normally i would just add the enemies to the parent layer using a CCMoveTo action to animate him over the screen but I want my enimies to follow the foreground of the parallax layer.
I'am increasing the scroll speed slowly as the game progresses.
I can't seem to figure out the right offset when calling
CGFloat offset = self.gameBackground.position.x;
[self.gameBackground addChild:enimy z:5 parallaxRatio:ccp(0.1, 0.1) positionOffset:ccp(offset, 85)];
Can someone help me out with this?
edit:
I'am doing this to move the background:
- (void)update:(ccTime)delta
{
self.speed -= 0.5f;
CGPoint backgroundScrollVel = ccp(self.speed, 0);
self.gameBackground.position = ccpAdd(self.gameBackground.position, ccpMult(backgroundScrollVel, delta));
}
Thanks
Rays article: http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game
Final solution:
I ended up just adding the enimies to the CCLayer instead of the Parallax. To move the enimies in the same speed as the foremost layer child in Parallax i did the following:
in update:(ccTime)delta:
CGFloat parallaxRatio = 0.1f;
CGPoint backgroundScrollVel = ccp((self.backgroundSpeed * - 1) * parallaxRatio, 0);
for(WKEnimy *enemy in self.enimies)
{
enemy.position = ccpAdd(enemy.position, ccpMult(backgroundScrollVel, delta));
}
You could add your enemy CCSprites to your foreground CCLayer (instead of directly adding them to your CCParallaxNode). Besides, I wouldn't recommend using actions (such as CCMoveTo) for this particular case; you may update your sprites positions as your doing with your gameBackground, and 'manually' check wether or not they're off the screen.

Cocos2d Parallax Loop

I've searched all of the forums and cannot find a working solution to get my parallax layer to loop. YES - I've tried all of the tutorials, includine the Space shooter by Ray Wenderlich but I'm struggling. Here's the code:
CCParallaxNode *parallax = [CCParallaxNode node];
// My Parallax Layer
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
CCSprite *midground = [CCSprite spriteWithFile:#"trees.png"];
midground.anchorPoint = ccp(0,0);
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_Default];
[parallax addChild:midground z:-9 parallaxRatio:ccp(1.4f, 1.4f) positionOffset:ccp(0,0)];
//Please loop once off screen
The image is 960x640 and i would like it to update and loop once it leaves the page. Any help much appreciated.
Try this simple solution:
http://www.gomonkey.it/2012/02/cocos2d-scorrimento-del-background/
You have need 2 images

Stars for scrolling shooter with CCParticleSystemQuad?

My code for init function:
NSArray *starsArray = [NSArray arrayWithObjects:#"Stars1.plist", #"Stars2.plist", #"Stars3.plist", nil];
for(NSString *stars in starsArray) {
CCParticleSystemQuad *starsEffect = [CCParticleSystemQuad particleWithFile:stars];
[self addChild:starsEffect z:-1];
}
The problem is that these particles appear and fully fill the screen rectangle during few seconds. But I need the sky full of stars from the beginning.
According to the answer at cocos2d starting particles from a specific time in the future , you can manually update the particle system. Example in cocos2d-x:
CCParticleSystemQuad *particle = CCParticleSystemQuad::create("res/Particles/Stars1.plist");
for (int i = 0; i < 10; ++i) {
particle->update(.1);
}
You may need to change the interval to suit the particles.
Add them to a layer, hide the layer, then unhide the layer after everything is done loading. That way you can set stuff up and not have it display right away.
That's just one approach. Another idea is to load all your images into Cocos before game play and game logic processes begin. That way there is no pause and delay while images are loading.

Cocos2D - Particles follow the emitter instead of staying at the position they were released

In cocos2D I currently have a very simple particle emitter initialized like this:
turnEmitter = [[CCParticleFlower alloc] init];
turnEmitter.texture = [[CCTextureCache sharedTextureCache] addImage:#"Pocket.png"];
[self addChild:turnEmitter z:1];
turnEmitter.scale = 0.7f;
turnEmitter.positionType = kCCPositionTypeFree;
It is simply added directly to the gameplay layer.
This emitter follows a sprite around the screen in this way (happens in the update method):
turnEmitter.position = turnEmblem.position;
Now the problem is that the tail of particles left behind the emitter moves with the emitter, instead of released particles simply staying in the position they were released, which gives a really weird and stupid looking effect.
What I want to do is have the particles not follow the emitter at all after they have been spawned, unfortunately I have been unable to find any way of doing so.
As you can see from the code above I have already searched around, and found people which suggests changing the positionType property of the emitter, although I have tried all the possibilities and it does not solve the problem.
Does anyone have any ideas as to what this might be?
You may want to try changing the "emitterMode" as well to "kCCPositionTypeFree". I had a similar issue where i had the emitter as a child of a CCNode. The CCNode was being rotated, but the particles and emitter wasn't. In the same way it looked stupid because the illusion of rotation was ruined. I need to set the following on my emitter:
emitter.emitterMode = kCCPositionTypeRelative;
emitter.positionType = kCCPositionTypeRelative;