Cocos2d-x has parallaxnode parallax node, the inspection as the name implies, is caused by different movement rate effect.
I think we all played the legend of the turret, his background has a vision and a close-up point, and you swipe the screen when the vision and close-up at different rates of movement;
Today we are here to achieve this effect.
Key words: ScrollView, Parallaxnode
To slide definitely need to scrollview, we generally use Cocostudio to build a scrollviewd component, in the Cocostudio set up a variety of properties we need to import the project can be directly sliding;
Cocos2d-x 3.2 Read Cocostudio Project interface has undergone a small change, Cocostudio drew a scrollview, read into the project;
Auto RootNode =cocostudio::timeline::nodereader::getinstance ()->createnode ("scrollviewtest_1/ Scrollviewtest_1.exportjson");
RootNode is equivalent to a layer, we need to take scrollview to control;
1 Auto child = Rootnode->getchildbytag (9); 2 Auto scroll = Static_cast<scrollview *>(child); 3 Scroll->setparent (nullptr); // 4 Auto visiablesize = Director::getinstance (),getvisiblesize (); 5 Scroll->setcontentsize (visiablesize); Let ScrollView the visual range and screen size, otherwise there will be an adaptation problem;
It is important to note that the ScrollView visual area size and the concept of the size of the sliding area, the visible area is equivalent to a window, the ScrollView sliding area is larger than the visible area, so that the effect of sliding; now we scrollview ready. Below you need to create Parallaxnode:
1Auto BG1 = Sprite::create ("Helloworld.png");2Auto Bg2 = Sprite::create ("Helloworld.png");3Auto Sprite = Sprite::create ("Closenormal.png");4 5Parallax =parallaxnode::create ();6Parallax->addchild (BG1,1, VEC2 (0.5f,0), VEC2 ( -, -) );//The second parameter is ZOrder, the third parameter represents the movement speed, and the third parameter represents the relative position of the child7Parallax->addchild (Bg2,1, VEC2 (0.5f,0), VEC2 (Bg1->getcontentsize (). Width, -));8Parallax->addchild (Sprite,2, VEC2 (1.1,0), VEC2 ( -, -));9 //This->addchild (parallax);TenScroll->addchild (parallax); Finally, we need to put the Parallax node inside the ScrollView.
Parallaxnode parallax nodes to achieve different levels of vision