helloworld 基础篇(本人初学,未免很多不足,希望多给予批评)
首先 安装及配置就不细说了,网上有很多参考。先来说说目录结构 resource ,libs ,Classes ,resource 是资源文件夹,存放一些图片等,libs 是存放的类库文件,Classes 类似于java中的编译好类的文件。include 文件中包含 .h 文件 类似于java 中的接口Interface 只是有方法声明,没有具体实现方法,.cpp文件和.h 文件相互对应,及.cpp文件 实现.h文件中声明的方法。如果涉及到多个类之间的方法调用,需要加入 #include "cocoa/CCObject.h" 类似于java的引用相应的类,这样就可以类之间的方法灵活调用。
下面来说说demo 中的程序入口,其中的main.cpp 跟java的主函数相似,是程序的入口,看看mian.cpp里面的方法
#include "main.h" #include "AppDelegate.h" #include "CCEGLView.h" USING_NS_CC; // uncomment below line, open debug console // #define USE_WIN32_CONSOLE int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); #ifdef USE_WIN32_CONSOLE AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); #endif // create the application instance AppDelegate app; CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setFrameSize(480, 320); int ret = CCApplication::sharedApplication()->run(); #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif return ret; }
可以看到在此类中 涉及到了AppDelegate.cpp 下面看下这个类:
#include "cocos2d.h" #include "CCEGLView.h" #include "AppDelegate.h" #include "MapScene.h" #include "SimpleAudioEngine.h" using namespace CocosDenshion; USING_NS_CC; AppDelegate::AppDelegate() { } AppDelegate::~AppDelegate() { SimpleAudioEngine::end(); } 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 = MapScenes::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()->stopAnimation(); SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } // this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { CCDirector::sharedDirector()->startAnimation(); SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); }
如果想运行自己创建的一个类 可以更改此处代码:
// create a scene. it's an autorelease object CCScene *pScene = MapScenes::scene(); // run pDirector->runWithScene(pScene);
把场景设置为自己的类,然后在编译器中将工程设置为默认启动,既可以运行自己创建的类中的方法了!
相关推荐
自己记录的Cocos2d-x学习笔记,希望能够帮助新手,快速入门,掌握cocos2d-x的开发
Cocos2d-x学习笔记——完全掌握C++ API与游戏项目开发.zip
cocos2d-x学习笔记\cocos2d-x学习笔记(17)--简单游戏实例1--双枪手
自己在学习的时候记得笔记,希望对大家有帮助,如有错误期待指出!
cocos2d-x学习笔记(5)-- CCScene场景的切换(带过度效果).rar
资源名称:Cocos2d-x学习笔记——完全掌握JS API与游戏项目开发资源截图: 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
老G的cocos2d-x学习笔记 第一部分:基本图形绘制 第二部分:字符串绘制 第三部分:绘制图片 cocos2d-x学习笔记04:简单动画 cocos2d-x学习笔记06:如何将win32移植到android ....
Cocos2d-x学习笔记(三)—— 坐标系
cocos2d-x学习笔记(16)--spritesheet(精灵表单).rar
cocos2d-x学习笔记(13)--schedule .rar
cocos2d-x学习笔记(17)--简单游戏实例1--双枪手
Cocos2D-X开发学习笔记-按键事件使用示例 教程地址:http://blog.csdn.net/yangyu20121224/article/details/10040985
cocos2d-x学习笔记(10)--touchEvent.rar
cocos2d-x学习笔记(4)--CCLayer背景绘制 .rar
cocos2d-x学习笔记(20)-- box2d入门 .rar
cocos2d-x学习笔记(14)--CCTextureCache .rar
cocos2d-x学习笔记(6)-- menu.rar
cocos2d-x学习笔记(12)--粒子系统 .rar
cocos2d-x学习笔记(9)--effect(特效).rar