[Cocos2D-X] initial view door diameter (7) unlimited map Rolling

Source: Internet
Author: User

The principle of rolling a map is simple, that is, you can set the location of the map continuously. The schedule () function is used for specific implementation. [Cpp] pMap = CCSprite: create ("MapHenn.png"); pMap-> setPosition (ccp (mSize. width/2, mSize. height/2); this-> addChild (pMap, 0); schedule (schedule_selector (SpriteScene: updateMap), 0.1f); the role of the schedule () function is based on the specified time, call a function continuously. Then, update the map position in updateMap. [Cpp] void SpriteScene: updateMap (float dt) {pMap-> setPositionX (pMap-> getPositionX ()-5);} Ctrl + F5, you can see that the map continues to scroll to the left. Another problem is that if you scroll to the far right of the map, there will be no background. Just add a limit in updateMap. [Cpp] void SpriteScene: updateMap (float dt) {pMap-> setPositionX (pMap-> getPositionX ()-5); // If the map scrolls to the rightmost, restore the initial position if (pMap-> getPositionX () <-pMap-> getContentSize (). width/2 + mSize. width) {pMap-> setPosition (ccp (mSize. width/2, mSize. height/2);} here, only the map is scrolled to the left, and the right is scrolled. If you add a dynamic role in the scenario and then scroll the map, it will lead to the walking effect of the character. This is the principle of the 2D Lock Angle game.:

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.