Hi all,
I created some really small classes to help you building a scrolling layers with parallax. The code is based on some posts I found in this forum.
Feel free to modify/adapt/use/abuse :-)
The code is Public Domain
Small example of usage:
// main parallax node
GFFParallaxNode *voidNode = [GFFParallaxNode node];
// first background
RepeatableLayer *bg01 = [RepeatableLayer layerWithFile:@"BG01.png"];
[voidNode addChild:bg01 z:0 parallaxRatio:0.5f];
RepeatableLayer *bg02 = [RepeatableLayer layerWithFile:@"BG02.png"];
[voidNode addChild:bg02 z:1 parallaxRatio:0.8f];
RepeatableLayer *fg01 = [RepeatableLayer layerWithFile:@"FG01.png"];
[voidNode addChild:fg01 z:4 parallaxRatio:1.1f];
// run some tests
[voidNode runAction:[RepeatForever actionWithAction:[CallFunc actionWithTarget:voidNode selector:@selector(scrollTest)]]];
the method scrollTest just calls scroll with a fixed parameter of 0.3f. In order to move the main parallax node, you *must* call scroll and not just set the position. You might want to override setPosition: to make it work with common Move* actions.
RepeatableLayer is a Sprite subclass and GFFParallaxNode is just a CocosNode subclass.
Oh, it only works for horizontal scrollers, but with a small ammount of work, you can make it scroll vertically :-P