First briefly introduce myself: 2011 began to use cocos2d-x to do mobile games, until 2014, during a few mobile online games. This year, we started our company's transformation and started to engage in Android. We were lucky to have a weekend break and seldom worked overtime. In addition, we used to like playing six games (2 hits and 1.
Okay, let's talk about it. Just get it done!
1. Search for image resources
Initially, I was planning to use PS for resources. I found that my PS level was too low, so I found a game on the Internet and pulled out the resources, I used psto process the resources that I just pulled out. The resource is OK ^!
2. Development Environment Construction
Use is how to build cocos2d-x 3.2 ask du Niang ^!
3. Development is still necessary step by step (first build a static chessboard and chess piece)
Class chessboard: Public cocos2d: node {public: Virtual bool Init (); create_func (chessboard); // reset the checker void reset (); protected: point maboardpoints [4] [4]; byte maboarddata [4] [4] ;}; bool chessboard: Init () {// 1. super init first if (! Node: Init () {return false;} size visiblesize = Director: getinstance ()-> getvisiblesize (); vec2 origin = Director: getinstance () -> getvisibleorigin (); // the chessboard basemap int I = 0, j = 0; Auto BG = sprite: Create ("muwen.png"); If (BG! = NULL) {int IX = 0, Iy = 0, IW = 0, ih = 0; IW = BG-> getcontentsize (). width; ih = BG-> getcontentsize (). height; ix = Ceil (visiblesize. width/IW); Iy = Ceil (visiblesize. height/iH); for (I = 0; I <IX; I ++) {for (j = 0; j <Iy; j ++) {auto temp = sprite:: Create ("muwen.png"); temp-> setanchorpoint (ccpointzero); temp-> setposition (CCP (I * IW, J * IH )); addchild (temp) ;}}// card Black Box 3*3 Auto cell = sprit E: Create ("point.png"); If (cell! = NULL) {int ilinew = 18; int x = visiblesize. width/2-1.5 * cell-> getcontentsize (). width; int y = visiblesize. height/2-1.5 * cell-> getcontentsize (). height; for (I = 0; I <3; I ++) {for (j = 0; j <3; j ++) {auto temp = sprite :: create ("point.png"); temp-> setanchorpoint (ccpointzero); point Pos = CCP (x + 1 * ilinew + I * (cell-> getcontentsize (). width-ilinew), Y + 1 * ilinew + J * (cell-> getcontentsize (). height-ilinew); temp-> setposition (POS); addchild (temp); maboardpoints [I] [J] = CCP (POS. X + 8, POS. Y + 8) ;}}// initialize the coordinates of the peripheral points for (I = 0; I <3; I ++) {maboardpoints [I] [3]. X = maboardpoints [I] [2]. x; maboardpoints [I] [3]. y = maboardpoints [I] [2]. Y + (maboardpoints [I] [2]. y-maboardpoints [I] [1]. y); maboardpoints [3] [I]. X = maboardpoints [2] [I]. X + (maboardpoints [2] [I]. x-maboardpoints [1] [I]. x); maboardpoints [3] [I]. y = maboardpoints [2] [I]. y;} maboardpoints [I] [3]. X = maboardpoints [2] [2]. X + (maboardpoints [2] [2]. x-maboardpoints [1] [2]. x); maboardpoints [I] [3]. y = maboardpoints [2] [2]. Y + (maboardpoints [2] [2]. y-maboardpoints [2] [1]. y); reset (); // pawn for (I = 0; I <4; I ++) {for (j = 0; j <4; j ++) {if (1 = maboarddata [I] [J]) {auto point = sprite: Create ("white_point.png "); point-> setposition (mabardpoints [I] [J]); addchild (point);} else if (2 = mabarddata [I] [J]) {auto point = sprite:: Create ("black_point.png"); point-> setposition (maboardpoints [I] [J]); addchild (point) ;}}return true;} void chessboard :: reset () {memset (maboarddata, 0, sizeof (maboarddata); // initialize 1-team int I = 0; for (I = 0; I <4; I ++) {mabarddata [I] [3] = 1;} mabarddata [0] [2] = 1; mabarddata [3] [2] = 1; // initialize 2 teams for (I = 0; I <4; I ++) {maboarddata [I] [0] = 2 ;} maboarddata [0] [1] = 2; maboarddata [3] [1] = 2 ;}
The above is the board class we are engaged in today, just simple
Here is the use of chess and card
bool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto board = Chessboard::create(); addChild(board); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it‘s an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it‘s an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); return true;}
For the four images,
Next, let's look at the running figure ^!
Cocos2d-x Game 1 together