Cocos2d-x to achieve simple flop effect

Source: Internet
Author: User

Cocos2d-x to achieve simple flop effect

I have found a lot of online results. The complexity is to rewrite a sprite class and simply implement it using the built-in engine action CCOrbitCamera, but there are some problems, the image is reversed after rotation.

I am only using a simple flop effect. After clicking it, I flip the image. After I flip the image to the other half, I switch to the other side and continue the rest of the rotation.

Note: The following code can only be used to flip the cards once, and the second one will be messy. Of course, all I need is to flip the cards once.

Simple image loading:

pSprite = CCSprite::create("iv_card_1.png");pSprite->setPosition( ccp(300,300) );this->addChild(pSprite, 0);
After the image is clicked, turn the card:

Void HelloWorld: menuCloseCallback (CCObject * pSender) {// = rotation time, start radius, radius difference, start z angle, rotation z angle difference, start x angle, rotate x angle difference === CCSequence * action = CCSequence: create (CCOrbitCamera: create (, 0, 0, 90, 0, 0), CCCallFunc :: create (this, callfunc_selector (HelloWorld: objectReset), CCOrbitCamera: create (1, 1, 0,-90,-90, 0, 0), NULL ); pSprite-> runAction (action);} void HelloWorld: objectReset () {// CCTexture2D * texture = CCTextureCache: sharedTextureCache ()-> addImage ("iv_card_2.png "); // pSprite-> setTexture (texture); CCSprite * p = CCSprite: create ("iv_card_2.png"); pSprite-> setTexture (p-> getTexture ()); /// === positive elements can be added ===== CCSprite * p2 = CCSprite: create ("public_diamond_icon.png"); pSprite-> addChild (p2 ); p2-> setPosition (ccp (pSprite-> getContentSize (). width/2, pSprite-> getContentSize (). height/2 + p2-> getContentSize (). height/2); // ========================== pSprite-> setScaleX (-1 );}


Clip Image






Related Article

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.