Hello World

新建一个cocos2d-x项目。

Hello World_第1张图片

Hello World_第2张图片

说明:cocos2dx 标准模板,cocos2dx_box2d物理游戏模板,cocos2dx_chipmunk物理游戏模板,cocos2dx_js脚本模板,cocos2dx_lua脚本模板。

本例使用cocos2dx


完成工程创建后,会发现整个工程有四个目录比较重要。

Resources:这里存放程序需要用到的资源图片

libs:这里存放有cocos2dx引擎类库和扩展库

classes:这里存放程序所需的代码

cocos2dx中有四个类比较重要

CCDirector,游戏的主导演,游戏的总流程控制,控制各个场景的切换,以及游戏的暂停或继续等。

CCScene ,游戏的场景类,每一关,或者每一屏,一个游戏由多一个或多个场景(CCScene)组成,一个场景(CCScene)由一个或多个层(CCLayer)组成。

CCLayer,图层类。场景中显示的每一层。

CCSprite,精灵类。游戏中的主角,敌人,物品。

//

//  Hello_Cocos2dxAppDelegate.cpp

//  Hello_Cocos2dx

//

//  Created by cloud on 13-4-8.

//  Copyright __MyCompanyName__ 2013. All rights reserved.

//


#include "AppDelegate.h"


#include "cocos2d.h"

#include "HelloWorldScene.h"


USING_NS_CC;


AppDelegate::AppDelegate()

{


}


AppDelegate::~AppDelegate()

{

}


bool AppDelegate::applicationDidFinishLaunching()//程序加载方法

{

    // initialize director

    CCDirector *pDirector = CCDirector::sharedDirector();

    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());


    // turn on display FPS

    pDirector->setDisplayStats(true);


    // 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;

}


// This function will be called when the app is inactive. When comes a phone call,it's be invoked too

void AppDelegate::applicationDidEnterBackground()//程序挂起

{

    CCDirector::sharedDirector()->pause();


    // if you use SimpleAudioEngine, it must be paused

    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

}


// this function will be called when the app is active again

void AppDelegate::applicationWillEnterForeground()//程序返回

{

    CCDirector::sharedDirector()->resume();

    

    // if you use SimpleAudioEngine, it must resume here

    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();

}


你可能感兴趣的:(Hello World)