cpCCSprite moving out of Window Containment in cocos 2d Spacemanager framework - cocos2d-iphone

I'm new to Cocos2D - spacemanager framework, and stuck at a problem.
I have created a window containment for the gravity using below code..
[spaceManager addWindowContainmentWithFriction:1.0 elasticity:1.0 inset:cpvzero];
Now I created a cpCCSprite object and added it to the CCScene.
I am trying to applyImpulse to this cpCCSprite object when a touch is detected near the sprite.
[sprite applyImpulse:cpvmult(vector, magnitude)];
This works fine when the magnitude is less, but if it is a high value say 1000 or 1500,
the sprite moves out of the window containment added and is disappearing from the screen for the detected touch.
I am using cocos v2.x with spacemanager framework v0.3.0.
Please help me in fixing this.

Related

How to detect the collision of three sprite in cocos2d-x 2.2?

I am new to cocos2d-x and I am implementing my own flappy bird.
Now I am working with the collision detection and I am stuck.
I added the down_pipe sprite and the up_pipe sprite to a parent sprite pipes, and I move the parent shift from right to left.
But when I check the collision by
if (bird->boundingBox().intersectsRect(pipes->boundingBox()))
It doesn't work.
And I try this way:
if (bird->boundingBox().intersectsRect(pipes->getChildByTag(DOWN_PIPE)->boundingBox()) || bird->boundingBox().intersectsRect(pipes->getChildByTag(UP_PIPE)->boundingBox()))
It still doesn't work.
How can I solve the problem? Any advice?
You try this,
CCRect target = CCRectMake(pipes->getPosition().x - (pipes->getContentSize().width/2),pipes->getPosition().y - (pipes->getContentSize().height/2),pipes->getContentSize().width,pipes->getContentSize().height);
if (bird->boundingBox().intersectsRect(target))

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.

CCLayerColor in SpriteKit

Is there something to replace CCLayerColor, CCLayerGradient etc inside Sprite Kit?
It was always easy to create simple filled rectangles in cocos2d, but I don't find any out of the box solutions in Sprite Kit so far.
As always, it should be platform independent so no iOS only code please (i.e., inside Sprite Kit).
Do you mean
SKSpriteNode *rect = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(70, 70)];

Combine Cocos2D (CCAnimation) animation with CocosBuilder (CCBAnimation Manager)?

I'm integrating CocosBuilder 2.1 into an existing Cocos2D-iphone 2.0 game and having some trouble with animations. There are multiple characters in the game that have both repeating sprite-based animations and movement animations, the latter being dynamically based on changing starting and ending positions.
This was easy in pure Cocos2D. I could just write something like:
action = [CCSpawn actions:
[CCRepeat actionWithAction:[CCAnimate actionWithDuration:1.0f animation:flippingAnimation restoreOriginalFrame:YES] times:x],
flippingAction, nil];
However, CocosBuilder uses the CCBANimationManager, which appears to run on an entirely different system. More like:
CCBAnimation Manager *animationManager = self.userObject;
[animationManager runAnimationsForSequenceNamed:#"Flipping"]
I can design the sprite animations in CocosBuilder, but I think my movement animations will have to stay in Cocos2D code. Is there any way to run the two types of animation simultaneously on the same CCSprite?
Thanks for your help.

Achieve Infinite Scrolling for a platformer game using cocos2d language objective c

I am trying to develop an 2D game using cocos2d library. I am still learning the framework.
Please understand that I am new to game development but not new to programming using objective c.
Here is the issue I am facing when it comes to my game development effort - I feel that I am missing the theoretical understanding of how to develop an infinite scrolling game. Is it possible for any of you to provide me some guidance on that ?
Here is my understanding of achieving infinite scrolling using cocos2d framework:
Cocos2d has a singleton director class which handles the current scene and scene transitions
In the current scene, I feel like I have to create an platform object consisting of several images and add them as a child to the current layer. And constantly run a move action to the platform sprite. So as and when I detect a particular image is off screen I have to replace it with another image. That way I will be able to create an infinite scrolling.
I am sorry if point 2 is not coherent. I just attempted to put my understanding of how to infinite scrolling.
Can you please help me with this ?
Thanks
I dissected how to implement scrolling with cocos2d-iphone in this article. What you probably want is the "fake scrolling" approach where two background images are moved and switch position after one completely left the screen.
You want to do this for the background layer only, not individual sprites. Your world isn't really moving, it's just the background panning that creates the illusion of movement. All sprites etc (player, enemies) movement is still relative to screen coordinates.
You'll find a working implementation in the code for my Learn Cocos2D 2 book in the Shoot'em Up project.
If you don't want to bother implementing this yourself, KoboldTouch supports endless/infinite scrolling for tilemaps. Here the game objects actually move along with the background infinitely (up to the maximum coordinates supported by float which is around +/- 16 million points).