i have a question about parallax scrolling with cocos2d. I currently using the newest version 3.3. I have a similar scenario like in tiny wings. I have foreground and a background which should be moved with a different speed to get the parallax effect.
As i said it's similar to tiny wings, so try to explain on tiny wings example. In the game there are these islands. One island has one background. When you fly to a new island you can see the parallax scrolling of the the different backgrounds. They merge in each other in the middle of the space between two islands.
My problem is that i don't get the correct width of one background in addition to his island. In my game i scale the foreground when the player reach a height for example.
Here are the initialization from parallaxScroller:
CCParallaxNode * _parallaxScroller = [CCParallaxNode node];
[_parallaxScroller addChild : background z:1 ratio:ccp(0.6, 0) offset : ccp(0, 0)];
[_parallaxScroller addChild : foreground z:2 ratio:ccp(1, 1) offset : ccp(0, 0)];
To get the hero on the right position i use the following code:
float playerToScreenOffsetFactor = 0.9;
float offsetX = _hero.position.x;
float positionForForeground = (_winSize.width/playerToScreenOffsetFactor-offsetX*newScale)
_parallaxScroller.position = ccp(positionForForeground, _parallaxScroller.position.y);
I got much of the code from tiny wings on github:
But all this does not work. The background move uncontrolled his x Coordinate, because the scale can be change immediately.
So i want to show that i tried much to get the result, without success.
My question is know: does anyone know a good example of this kind of parallax scrolling or a tutorial? Or a suggestion how could i get what i want?
Thank you in advance.
Greetings
Aucun commentaire:
Enregistrer un commentaire