cocos2dxHellowoed 发现 2.2.3

cocos2d	笔记
	文件夹介绍
		cocosdx ----->cocos2d主要代码
		CocosDenshion---->cocos2d的声音的
		Document------>文档
		extensions ---->cocos2d一些拓展
		projects ----->一些project
		samples------>cocos2d的一些提供的案例
		scripting ----->脚本
		template ------>模板
		tools   ------->工具
	project介绍
		Classes ----->是夸平台的代码
		Resources ---->资源(声音,脚本)
		proj. ----->是不能够跨平台的代码
	主要參数
		CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setViewName("名字");
    eglView->setFrameSize(长, 宽);//主要是界面
 		------------------------------------------------------------------------------
 		
    bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);//使pEGLView和pDirector关联,通过setOpenGLView进行关联
	
    // turn on display FPS
    pDirector->setDisplayStats(true);//是左下角的显示的fps一般分布会关闭

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);//每针多少秒

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
	CCScene* HelloWorld::scene(){
	    // 'scene' is an autorelease object
	    CCScene *scene = CCScene::create();//创建一个scene
	    
	    // 'layer' is an autorelease object
	    HelloWorld *layer = HelloWorld::create();//创建一个城
	
	    // add layer as a child to scene 
	    scene->addChild(layer);//把scene加入到城
	
	    // return the scene
	    return scene;//在返回scene
	}
	
	bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )//调用父类的init
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 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
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));//创建那个button
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    return true;
}

	CCDirector 导演
		 设置全局属性。推动剧情发展,单例对象
			 CCDirector* director = CCDirector::sharedDirector();			 	
	CCScene	是场景的意思
			游戏有多个场景构成。可是某一时刻仅仅有一个场景在执行
			CCScene是一个独立的工作流,场景类在cocos里,一般仅仅作为容器。装载其它游戏元素
	CCLayer    层类
   		归类
  	 	处理触摸消息
   		CCColorLayer(颜色), CCMenu
	CCSprite 精灵类
			 抽象游戏角色(主角。敌人,道具。。

。。)体现游戏外观(包括了纹理),通过改动属性来改变精灵的位置、颜色、。

。。,或者是执行动作让精灵变得生动 CCNode 渲染树的节点类,全部可渲染对象都从CCNode派生 using namespace cocos2d; == USING_NS_CC; 一般用后面的 // 实现create的静态函数,create函数会自己主动调用init函数 CREATE_FUNC(MyLayer); 第一个scene 用runWithScene pDirector->runWithScene(pScene); 以后scene 用replaceScene CCDirector::sharedDirector()->replaceScene(MyLayer::scene()); setTouchEnabled(true); 支持触摸 假设不写不赞成触摸 setTouchMode(kCCTouchesAllAtOnce); 多点触摸:比方双手按在手机屏幕什么 setTouchMode(kCCTouchesOneByOne)。 单点触摸:比方单手按在手机屏幕什么 bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);//当你手指刚刚按下是时候 void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//当你手指移动按下是时候 void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);//当你手指离开按下是时候 void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);//当你电话来的时候 CCPoint pt = pTouch->getDelta();//返回的距离 CCPoint pos = _lable->getPosition();//获取_lable的位置 _lable->setPosition(ccpAdd(pos,pt));//改变_lable的位置


原文地址:https://www.cnblogs.com/cynchanpin/p/6709977.html