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