Parallaxnode parallax nodes to achieve different levels of vision

Source: Internet
Author: User
Tags addchild

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.