Use of Cocos2d-x3.2 speed and follow

Source: Internet
Author: User

 
// Gamescene. h # include "cocos2d. H "class gamescene: Public cocos2d: layer {public: static cocos2d: Scene * createscene (); Virtual bool Init (); void menucallback (cocos2d: ref * psender ); create_func (gamescene );};




// Gamescene. CPP # include "gamescene. H "using_ns_cc; cocos2d: Scene * gamescene: createscene () {auto scene = scene: Create (); // create a scenario auto layer = gamescene :: create (); // create a layer scene-> addchild (layer); Return scene;} // initialize the current layer bool gamescene: Init () {If (! Layer: Init () // initialize the parent class return false; // obtain the screen size visiblesize = Director: getinstance ()-> getvisiblesize (); // auto size = Director: getinstance ()-> getwinsize (); // Add an image sprite auto sprite = sprite: Create ("onepiece_1.png "); sprite-> setposition (vec2 (visiblesize. width/2, visiblesize. height/2); this-> addchild (sprite); Auto sprite1 = sprite: Create ("icon.png"); sprite1-> setposition (vec2 (visiblesize. width * 0.2, visiblesize. height/2); this-> addchild (sprite1); Auto moveTo = moveTo: Create (2, vec2 (visiblesize. width * 0.8, visiblesize. height/2); // sprite1-> runaction (moveTo); // auto speed = speed: Create (moveTo, 2 ); sprite1-> runaction (speed); // The background follows auto follow = follow: Create (sprite1); this-> runaction (follow); Return true ;}


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.