how can we Add Parallax Scrolling in Cocos 2D? - ios

how can we Add Parallax Scrolling in Cocos 2D version 3 (IOS) . I have explored many tutorials but nothing has helped me. i have tried following code but its not working . can you please list down steps to achieve Parallax Scrolling in Cocos2D game. i ma newbie in game Development . your help will be highly appreciated. Thanks
CCParallaxNode *voidNode = [CCParallaxNode node];
[voidNode addChild:bg4 z:1 parallaxRatio:ccp(3.5f, 3.5f) positionOffset:ccp(3.5f, 3.5f)];
[voidNode addChild:_spacedust1 z:2 parallaxRatio:ccp(3.5f, 3.5f) positionOffset:ccp(3.5, 3.5)];
[self addChild:voidNode];

You just move the voidNode. All children that you add to voidNode will be moved relative to voidNode.
So for example the foreground should be moved exactly like the voidNode then you make a parallaxRatio of ccp(1.f, 1.f).
Then the background for example should be moved slower than the foreground you make a parallaxRatio of ccp(0.6f, 0.6f).

Related

Is there a way to create a scrolling background(right to left) using Core Animator for Mac? (Swift 2 / Xcode)

I have the Core Animator software and I was wondering if there was any way to animate a scrolling background to export into Xcode?
Thank you!
Yea there is. Have you run through the tutorials, or the sample projects? They might help you get started.
What you would want to do is make your background loop animation and then modify the generated source so the animation loops forever.
backgroundAnimation.repeatCount = .infinity
Not clear from your question if it's about Core Animator itself or the code to make it loop forever.

Temporary disable physics from CCSprite

I'm currently discovering Cocos2D in combination with SpriteBuilder and I'm making stuff bounce around.
It's quite fun :)
What I'm trying to figure out is the following :
- On SpriteBuilder, I create a CCSprite, and I enable physics for this one.
- I can invoke it in XCode, and do whatever I want with it. Plus, the sprite is reacting accordingly to the physics settings applied to it. Great.
Now, what I would like to do is to disable the physics from this sprite in the code. I don't find a method in the Cocos2D API that would do the trick.
Can you help me out ?
Thank you for your time and help ;)
I write the correct answer then:
sprite.physicsBody.sensor = TRUE;

Strange bug in iOS 7 UIImage (not showing or showing after delay)

Every time when we add UIImageView or simple UIView with some custom CALayer objects added to "layer" property to view hierarchy, there are some different scenarios:
1) all images (in uiimageviews and calayer) are drawn with random delay
2) some images are drawn, but some not, when we perform a simple touch event anywhere - they appear
3) some images are not drawn and they won't appear after simple touch events, the only way make them to appear is to minimize the app and to expand it again.
The last case appears much less than two others. That problem occurs only on iOS7, iOS 4.3-6.1 is totally OK. We have viewed a lot of possible solutions but they were pretty primitive and none of those helped.
Any help would be appreciated! Thanks in advance!
we solved the problem. For everyone, who has the same problem, - all you need is to create CALayer and UIImageView objects on main thread, while UIImage objects still could be created in background thread. All these fixes are needed only in iOS 7

Ccocs2d UIScrollView Stops Touch Response

I am using a uiscrollview in my cocos2d project, using modification of some cocos2d files and the great CCScrollView class I got from a SO link. It is working fine but when I move to a next scene, the new scene is not responding to touches (whereas it was working fine before).
I am using iOS 5.1 & cocos2d 2.x.
Any suggestions?
Ok, you need to do this:
[aScrollView removeFromSuperview];
I'm not quite sure why since in the dealloc of CCScrollView you have:
[self removeFromSuperview];
I guess its being retained somehow? Anyway, it works.

How can I make the motion smoother?

I'am programming my first game for Ipad. I have a little problem on an animation. In this game I have a ball bouncing around the screen. I move the ball in this way
CGRect frameRect = ball.frame;
frameRect.origin.x += ballMovement.x;
frameRect.origin.y += ballMovement.y;
ball.frame=frameRect;
The ball moves but the animation is sometimes not very smooth... The strange thing is that while I was testing my app on my ipad I discovered that if I close the app and reopen it from the multitasking bar the ball moves way way better! The animation is smoother and faster...
Can somebody explain why is happening this thing?
Thank you!! Daniel from Italy
If reopening the application makes it smooth, then most likely something has been cached the second time that was not cached the first time. There's nothing in the 4 lines of code you posted that could explain the lack of smoothness. Maybe posting more of the code would help.

Resources