void addChild(cocos2d::Node *child,
int
z,
const cocos2d::Vec2 ¶llaxRatio,
const
cocos2d::Vec2 &positionOffset);
z:Z轴顺序
parallaxRatio:视差的移动速率
positionOffset:子节点位置坐标,该坐标是相对父节点的,即ParallaxNode
variable /'veərɪəb(ə)l/
可变的
auto front =
Sprite::create("hole_stencil.png");
auto mid = Sprite::create("hole_effect.png");
auto background = Sprite::create("HelloWorld1.png");
//创建一个视差节点
auto voidNode = ParallaxNode::create();
//添加需要移动的子节点
voidNode->addChild(background, 0, Vec2(0.4f, 0), Vec2(240, 160));
voidNode->addChild(mid, 1, Vec2(2.2f, 0), Vec2(450, 100));
voidNode->addChild(front, 2, Vec2(3.0f, 0), Vec2(500, 160));
ActionInterval* go = MoveBy::create(4, Vec2(-240, 0));
ActionInterval* goBack = go->reverse();
auto seq = Sequence::create(go,goBack, NULL);
voidNode->runAction(RepeatForever::create(seq));
auto mid = Sprite::create("hole_effect.png");
auto background = Sprite::create("HelloWorld1.png");
//创建一个视差节点
auto voidNode = ParallaxNode::create();
//添加需要移动的子节点
voidNode->addChild(background, 0, Vec2(0.4f, 0), Vec2(240, 160));
voidNode->addChild(mid, 1, Vec2(2.2f, 0), Vec2(450, 100));
voidNode->addChild(front, 2, Vec2(3.0f, 0), Vec2(500, 160));
ActionInterval* go = MoveBy::create(4, Vec2(-240, 0));
ActionInterval* goBack = go->reverse();
auto seq = Sequence::create(go,goBack, NULL);
voidNode->runAction(RepeatForever::create(seq));
addChild(voidNode);
其三个子节点由于设置的速率不同,移动快慢有一个非常明显的效果