[Cocos2d-x for WP8 study notes] HelloWorld structure analysis
First look at the directory structure:
Assets: The game resource files, pictures, audio, Resource folder has a similar function
include: The header file for placing the game
Shaders: The renderer shader file (FOG)
cocos2dorig.cpp/.h: Direct3D game default entrance, the default file name, and project name, in Cocos2dx, through here to start AppDelegate
//WP8Direct3D game default start entrance IFrameworkView^ Direct3DApplicationSource::CreateView() { return ref new PhoneDirect3DAppDemo(); } [Platform::MTAThread] int main(Platform::Array<Platform::String^>^) { auto direct3DApplicationSource = ref new Direct3DApplicationSource(); CoreApplication::Run(direct3DApplicationSource); return 0; } //Cocos2dx start entrance IFrameworkView^ Direct3DApplicationSource::CreateView() { return ref new cocos2dorig(); } ref class CCApplicationFrameworkViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource { public: virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() { return cocos2d::getSharedCCApplicationFrameworkView(); } }; [Platform::MTAThread] int main(Platform::Array<Platform::String^>^) { //auto direct3DApplicationSource = ref new Direct3DApplicationSource(); //CoreApplication::Run(direct3DApplicationSource); AppDelegate App; auto frameworkViewSource = ref new CCApplicationFrameworkViewSource(); Windows::ApplicationModel::Core::CoreApplication::Run(frameworkViewSource); return 0; }
AppDelegate.cpp/.h:
General entrance game files, control the life cycle of the game
bool AppDelegate::applicationDidFinishLaunching()
The game started to call this method
bool AppDelegate::applicationDidFinishLaunching() { // Initialize game engine controller CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // The development stage can open FPS to observe the fluency //pDirector->setDisplayFPS(false); // Set the horizontal screen display pDirector->setDeviceOrientation(CCDeviceOrientationPortrait); // Set per second refresh rate is FPS, the default 60 times per second //pDirector->setAnimationInterval(1.0 / 60); // Create scene CCScene *pScene = HelloWorld::scene(); // Running scene pDirector->runWithScene(pScene); return true; }
void AppDelegate::applicationDidEnterBackground()
The game into the background of the operation, in general, to pause the game
void AppDelegate::applicationWillEnterForeground()
The game back to front desk when the corresponding operation
HelloWorldScene.cpp/.h
HelloWorld game scene, in the AppDelegate:: applicationDidFinishLaunching () to create and run.
CCScene* HelloWorld::scene()
Scene creation
CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // Create an empty scene scene = CCScene::create(); CC_BREAK_IF(! scene); // Create a HelloWorld layer HelloWorld *layer = HelloWorld::create(); CC_BREAK_IF(! layer); // The HelloWorld layer is added to the scene scene->addChild(layer); } while (0); return scene; }
bool HelloWorld::init()
Initialize the HelloWorld class
bool HelloWorld::init() { bool bRet = false; do { //Call the parent class method to initialize if ( !CCLayer::init() ) { break; } //Create a text label to layer CCSize size = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Times New Roman", 24); pLabel->setPosition( ccp(size.width * 0.5, size.height * 0.5) ); pLabel->setColor(ccc3(160, 80, 5)); this->addChild(pLabel, 1); //Create HelloWorld wizard and added to the layer CCSprite *b = CCSprite::create("HelloWorld.png"); b->setPosition(ccp(0, 0)); b->setPosition(ccp(size.width * 0.5, size.height * 0.5)); this->addChild(b); //Setup can respond to touch setTouchEnabled(true); bRet = true; } while (0); return bRet; }
In this paper, the fixed link: [Cocos2d-x for WP8 study notes] HelloWorld structure analysis
Posted by Alvis at December 14, 2013 - 8:41 AM