How cocos2d-x efficiently develop games

Source: Internet
Author: User

The abstract class interface must be reserved for every game version upgrade. Therefore, writing abstract classes can greatly improve programming efficiency, and can be used once and for all. In a turn-based game, it is unscientific to write the first level and the second level. At this time, you need to write an abstract class for the following levels of games;

Next I will share with you how to write abstract classes, as for its security I think don't worry, we are on the basis of the cocos2d-x game engine to write abstract classes, is a kind of encapsulation of common functions of cocos2d-x;

I am also trying to develop in this area. If I cannot write well, I hope you will comment and criticize me;

I wrote a class called the JieKouLayer class which can be inherited by all layers of the game;

# Pragma once # include "e: \ cocos2d-x \ cocos2d-x-2.2 \ cocos2d-x-2.2 \ cocos2dx \ layers_scenes_transitions_nodes \ cclayer. h "# include" cocos2d. h "class JieKouLayer: public cocos2d: CCLayer {public: JieKouLayer (void );~ JieKouLayer (void ); /*************************** public parameter list ********* * ***************************/cocos2d:: CCSpriteBatchNode * _ directionBatchNode; /*************************************** *************************************//* ******************* * ***********/cocos2d:: CCSize _ visibleSize; cocos2d: CCPoint _ origin; void getOriginVis (); /*************************************** **********************//**************** * ******************* setCacheBatch ****************** * ***********************************/cocos2d:: CCSpriteBatchNode * setCacheAndBatchNode (char * plist, char * pvr ); /*************************************** **************************************** *********************//***************** ************************ * ********/void setSpritePro (cocos2d:: CCSprite * sprite, float posx, float posy, float scale, int opacity, float anrPosx, float anrPosy ); /*************************************** **************************************** ***/};
#include "JieKouLayer.h"USING_NS_CC;JieKouLayer::JieKouLayer(void){this->_directionBatchNode=this->setCacheAndBatchNode("dhkey/direction.plist","dhkey/direction.pvr.ccz");}JieKouLayer::~JieKouLayer(void){this->_directionBatchNode->release();}void JieKouLayer::getOriginVis(){this->_visibleSize = CCDirector::sharedDirector()->getVisibleSize();this->_origin = CCDirector::sharedDirector()->getVisibleOrigin();}void JieKouLayer::setSpritePro(cocos2d::CCSprite* sprite ,float posx ,float posy,float scale ,int opacity,float anrPosx,float anrPosy){sprite->setPosition(ccp(posx,posy));sprite->setScale(scale);sprite->setOpacity(opacity);sprite->setAnchorPoint(ccp(anrPosx,anrPosy));}CCSpriteBatchNode* JieKouLayer::setCacheAndBatchNode(char* plist,char* pvr){CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plist);CCSpriteBatchNode* batchNode=CCSpriteBatchNode::create(pvr);batchNode->retain();this->addChild(batchNode);return batchNode;}

We include this abstract class in the game, and then inherit it using the multi-inheritance of c ++.

I want to add another point: we put the game cache Resources in the abstract class to instantiate it, so we don't have to write the cache multiple times.


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.