Action effects in Cocos2d-X, Cocos2d-X action Effects

Source: Internet
Author: User

Action effects in Cocos2d-X, Cocos2d-X action Effects

The Cocos2d-X provides a rich set of action Effects

For example, grid Animation


Distorted effects



3D tile fluctuation Effect


Program code:

# Include "ActionEffect. h "# include" HelloWorldScene. h "static const char * _ actionName [] = {" CCFadeOutBLTiles "," CCFadeOutDownTiles "," Hangzhou "," CCFlipX3D "," CCFlipY3D "," CCJumpTiles3D ", "CCLens3D", "CCLiquid", "medium", "CCRipple3D", "CCShaky3D", "medium", "medium", "CCShuffleTiles", "CCSplitCols", "CCSplitRows ", "CCTurnOffTiles", "CCTwirl", "CCWaves", "CCWaves3D", "CCWavesTiles3D"}; CCScene * ActionEffect: scene () {CCScene * s = CCScene :: create (); ActionEffect * layer = ActionEffect: create (); s-> addChild (layer); return s;} bool ActionEffect: init () {CCLayer :: init (); CCSize winSize = CCDirector: shareddire()-> getWinSize (); CCNode * c = CCNode: create (); _ c = c; int actionCount = sizeof (_ actionName)/sizeof (* _ actionName); for (int I = 0; I <actionCount; I ++) {/* CCSprite * bg = CCSprite:: create ("HelloWorld.png"); c-> addChild (bg); bg-> setPosition (ccp (winSize. width/2 + I * winSize. width, winSize. height/2); */CCLayerColor * layer; if (I % 2 = 0) {layer = CCLayerColor: create (ccc4 (192,192,192,255), winSize. width, winSize. height);} else {layer = CCLayerColor: create (ccc4 (128,128,128,255), winSize. width, winSize. height);} c-> addChild (layer); layer-> setPosition (ccp (I * winSize. width, 0);/* Set Title */const char * title = _ actionName [I]; CCLabelTTF * label = CCLabelTTF: create (title, "Arial ", 36); layer> addChild (label, 1000); label> setPosition (ccp (winSize. width/2, winSize. height-80);} CCScrollView * view = CCScrollView: create (winSize, c); view-> setDirection (kccscrollviewdirehorhorizontal); view-> setContentSize (CCSize (winSize. width * actionCount, winSize. height); addChild (view); c-> setPositionX (1-actionCount) * winSize. width); // can touch setTouchEnabled (true); setTouchMode (kCCTouchesOneByOne); return true;} bool ActionEffect: ccTouchBegan (CCTouch *, CCEvent *) {return true ;} void ActionEffect: testAction (int idx, CCLayerColor * layer) {CCSize winSize = CCDirector: sharedDirector ()-> getWinSize (); CCSprite * sprite = (CCSprite *) layer-> getUserObject (); if (sprite = NULL) {// sprite = CCSprite: create ("background3.png"); sprite = CCSprite :: create ("HelloWorld.png"); layer-> setUserObject (sprite); layer-> addChild (sprite);} const char * an = _ actionName [idx]; CCAction * action = NULL; sprite-> setPosition (ccp (winSize. width/2, winSize. height/2); CCMoveBy * moveBy = CCMoveBy: create (4, ccp (0, sprite-> getContentSize (). height/2-winSize. height/2); // the top right to the bottom left of the grid disappears // The first parameter: Time // The second parameter: grid size if (an = "CCFadeOutBLTiles ") {action = CCFadeOutBLTiles: create (5, CCSize (16, 12);} // collapse and disappear from top to bottom of the grid // The first parameter: Time // The second parameter: grid size if (an = "CCFadeOutDownTiles") {action = CCFadeOutDownTiles: create (5, CCSize (16, 12 ));} // The grid disappears from bottom left to top right if (an = "CCFadeOutTRTiles") {action = CCFadeOutTRTiles: create (5, CCSize (16, 12 ));} // The grid disappears from bottom to top if (an = "CCFadeOutUpTiles") {action = CCFadeOutUpTiles: create (5, CCSize (16, 12 ));} // create an X axis 3D reversal effect if (an = "CCFlipX3D") // affects touch {action = CCFlipX3D: create (5 );} // create an if (an = "CCFlipY3D") {action = CCFlipY3D: create (5 );;} // grid beating effect if (an = "CCJumpTiles3D") {// parameter: time, grid size, times, amplitude action = CCJumpTiles3D: create (5, CCSize (16, 12), 56, 5.0f);} // convex lens effect if (an = "CCLens3D") {// parameter: time, grid size, Center Coordinate, circle radius action = CCLens3D: create (5, CCSize (16, 12), ccp (winSize. width/2, winSize. height/2), 100);} // liquid effect if (an = "CCLiquid") {// parameter: time, grid size, speed, amplitude action = CCLiquid :: create (56, CCSize (16, 12), 56, 2.0f);} // if (an = "CCPageTurn3D") {action = CCPageTurn3D :: create (5, CCSize (16, 12);} // create a 3D water wave effect if (an = "CCRipple3D") {// parameter: time, grid size, coordinates, radius, speed, amplitude action = CCRipple3D: create (10, CCSize (16, 12), ccp (winSize. width/2, winSize. height/2), 100, 10, 50366f);} // create a 3D shaking effect if (an = "CCShaky3D") {// parameter: Time, shake grid size, shake range, whether to shake Z axis action = CCShaky3D: create (10, CCSize (16, 12), 2, true );} // create a 3D tile shake effect if (an = "CCShakyTiles3D") {// parameter: time, shake grid size, shake range, and whether to shake the Z axis action = CCShakyTiles3D :: create (5, CCSize (16, 12), 2, true);} // create a 3D broken tile effect if (an = "CCShatteredTiles3D") {// parameter: time, shake grid size, shake range, whether to shake Z axis action = CCShatteredTiles3D: create (1, CCSize (16, 12), 7, true );} // tile shuffling effect if (an = "CCShuffleTiles") {// parameter: time, grid size, random number action = CCShuffleTiles: create (5, CCSize (16, 12), CCRANDOM_0_1 () * 10000);} // multiline disappearance effect (vertical) if (an = "CCSplitCols") {// parameter: Time, number of rows action = CCSplitCols: create (5, 9);} // multiline disappearance effect (horizontal) if (an = "CCSplitRows") {// parameter: Time, row number action = CCSplitRows: create (5, 9);} // square disappears if (an = "CCTurnOffTiles") {// parameter: time, grid size, random Number action = CCTurnOffTiles: create (5, CCSize (16, 12);} // create a distortion effect if (an = "CCTwirl") {// time, grid size, coordinates, number of distortions, amplitude action = CCTwirl: create (5, CCSize (16, 12), ccp (winSize. width/2, winSize. height/2), 5, 5.0f);} // create a fluctuation effect if (an = "CCWaves") {// parameter: time, shaking grid size, fluctuation speed, amplitude, horizontal fluctuation, vertical fluctuation action = CCWaves: create (5, CCSize (16, 12), 5, 5.0f, true, false );} // create a 3D fluctuation effect if (an = "CCWaves3D") {// parameter: time, shaking grid size, fluctuation speed, amplitude action = CCWaves3D: create (5, CCSize (16, 12), 5, 5.0f);} // create a 3D tile fluctuation effect if (an = "CCWavesTiles3D") {// parameter: Time, shake grid size, fluctuation speed, amplitude action = CCWavesTiles3D: create (5, CCSize (16, 12), 5, 5.0f);} if (action) {sprite-> runAction (action) ;}} void ActionEffect: ccTouchEnded (CCTouch * t, CCEvent *) {CCPoint ptStart = t-> getStartLocation (); CCPoint ptEnd = t-> getLocation (); if (ptStart. getDistanceSq (ptEnd) <= 25) {// click // The subwindow in which the vertex exists // convert ptStart to the iner coordinate in ScrollView // determine the clicked LayerColorCCPoint ptInContainer = _ c-> convertToNodeSpace (ptStart ); CCArray * arr = _ c-> getChildren (); // All layercolorfor (int I = 0; I <sizeof (_ actionName)/sizeof (* _ actionName ); I ++) {CCLayerColor * layer = (CCLayerColor *) arr-> objectAtIndex (I); if (layer-> boundingBox (). containsPoint (ptInContainer) {testAction (I, layer); break ;}}}}
 

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.